rust performance in IDE and command line - rust

I am a beginner of rust. I wrote a project with one main.rs and two module files. The dev environment is CLion+Intellij Rust plugin on MacOS 11.1. The program is a simple CPU-intensive computation task. To measure its performance, I used following method:
let timer = Instant::now();
task(); // the main function of the task
println!("{:.2?}", timer.elapsed());
When I ran the program in CLion's IDE, it prints a running duration of like 500~700µs.
However, if I ran the program (~project/target/debug/project) from command line in Mac Terminal, it prints 3~7ms. That's a difference one magnitude, which really confused me.
How to explain this difference? And any advice to improve the performance in command line? Thanks for any comments.

run
$cargo build --release
and execute the binary that will be created in
~project/target/release/project
and compare with that instead.
Also, assuming that you're doing this already, but make sure to measure things many times and average the results; your computer is doing a whole lot of other things at the same time, and one task could be interrupted at any time.

I think I got the answer. I have misstated the problem. I was not running the program in MacOS's terminal actually, but in CLion's Terminal window, which I thought it is equivalent to the OS's terminal - but it turns out to be not now. If I run the debug version in real OS's terminal, it prints same performance (500~700µs). And I also tried a release version, it prints like 20~40µs. This is what I expected.

Related

does python 3 multiprocessing freeze_support() sets the starting method to spawn?

well recently I encountered some freezing in my applications in Long run.
my program uses an infinite while loop to constantly check for new processes from a redis db and if there is any job to work on it will spawns a new process to run it in the background.
so I had issue with its freezing after 20 minutes, sometimes 10 minutes. it took me one week to figure it out that the problem rise from lack of this line before my while loop:
multiprocessing.set_start_method('spawn')
it looks like python does not do that on Windows and since windows does not support fork it's gonna stuck.
anyway, it seems this will solve my problem but I have another question.
in order to make a exe file for this program with something like pyinstaller I need to add another line as below to make sure its not freezing in the exe execution:
multiprocessing.freeze_support()
I want to know does this freeze_support() automatically sets the start method to 'spawn' too? I mean should I use both of these lines or just running one of them is ok? if so which one should I use from now on?
In the case of windows, spawn is already the default method so it would not be necessary to run the set_start_method ('spawn') line of code.
The freeze_support () is a different thing that does not affect the definition of start methods. You must use it in this scenario to generate an .exe.

Does anyone have an idea how to find what or who is calling findstr.exe to run speratically?

I have Windows 10, and about a week ago I installed Avast Device Driver Updater and it did update my chipset, intel processor, and Intel RAID drivers, which were the only ones I allowed it to with no problems. However a couple of days after I started noticing that a CMD window just pops up out of no where and seemingly when it wants to, and it runs a bunch of FINDSDR commands on a bunch of directories that I don't have on my laptop. The window then closes before I have a chance to read any of the paths and quicker then I can catch it to copy anything. The problem is that I can not find the program, shell script, or anything that would be running that might be causing this to run.
I do know that it always tries the to find the same directories, and they fail every time. But I just cant read them... I checked and according to Avast, the Driver Updater does not run any scripts like this, so it should not be the updater process, and just to be sure, I have stopped it from Auto Loading at Boot, and I turned off all it's functions in the settings.
So, I would like to know if anyone knows of any tricks that would help me identify what is calling the findstr.exe, or a way to trap it, while it's running (though even it I trapped it, I don't know how I can use that info to find the culprit that is causing it to run. I am hoping some one know how I can figure out what or where its running from and whos making it run. Any ideas? Thanks a bunch in advance!

Kernel died, restarting in the middle of my simulation (spyder)

I am using the spyder interface with a python script that works through many time steps in succession. At a random point in my code, the process will terminate and the console will say "kernel died, restarting...". I tried running the same script in pycharm and the process also terminates, seemingly at a random point, with some exit code which I assume means the same thing.
Anyone have any tips on how to get rid of this problem? Even a workaround so I can get some work done. This is incredibly frustrating.
Note: I recently moved and got a new router and internet service, not sure if that might affect things.

Find a String version of a GroovyConsole Script in a Heap Dump

I've accidentally ran a script with an infinite loop in GroovyConsole. :-\
For the sake of Murphy's Law, I haven't save my work during 3 or 4 hours. So, before killing the GroovyConsole Process, I've dumped the heap, with the hope to find a String version of the Script that was running at this moment
Do you have a hint in which Class it can hide, or if it is possible ?
So, it happens that my guess was right. The groovy.ui.Console Object keeps an history of changes of the script. I give you the OQL query that gave me my script back for my greatest pleasure. I ran it in VisualVM with the OQL plugin, but I could have used jhat :
select x.history.elementData[x.history.elementData.length-2].allText.toString() from groovy.ui.Console x
Despaired groovy developers who've lost their code once might be releaved now :-) For sure I am
The string version of the script may exists in another object. I'd love to hear other solutions

What could cause an executable, called by a powershell script, to hang when it exits

I'm debugging a particularly strange problem...
As a part of my team's test suite, we run a powershell script that calls an executable I wrote in C#.
Every blue-mooned Tuesday, the executable will hang indefinitely until we kill the process. Most days it works just fine, and I haven't gotten it to repro.
The curious part is that this exe hangs after it's done doing all it's work. It's output the last line of data and the main thread is exiting. There's no multithreading in this process, and CPU is at 0% and thread count is 1.
All I/O (other than console writes) is done earlier in the execution, and there's no exception catching anywhere, so if something throws we should see it.
I don't need a definitive "this is the issue," but I have no idea what could cause this behavior. If you could respond with any theories on why this would be happening (no matter how far fetched) that'd be great.
Version info
OS: Windows 2008 R2
Powershell: v2 (comes with R2)
.NET: v4
Heh, this is worth a shot. Got
Console.ReadLine()
anywhere at the end of some line of logic?
I've got a behaviour like that on one of my "C" console program. It was well working started via "CMD.EXE" but when I use it via "POWERSHELL.EXE" it hang (systematicaly) at the end of exécution.
In this code, there are keyboard pooling loop (while (! _kbhit()), and at the moment I solve the problem by consuming (getch()) the keydown that fired the last loop. I don't understand exactly why.
In the Powershell script the result of the exe file is affected to a var.

Resources