Why does select() consume so much CPU time in my program?

Unfortunately, this is wrong interpretation of the numbers. I’ve faced this situation many times (and ask a question on stackoverflow too). The main reason, is VisualVM doesn’t show correct CPU time. It showing percentage of the thread time in RUNNING state. But from documentation on Thread.State: Thread state for a runnable thread. A thread in … Read more

cProfile for Python does not recognize Function name

The problem is that you imported send_email inside your method definition. I suggest you to use runctx: cProfile.runctx(‘send_email()’, None, locals()) From the official documentation: cProfile.runctx(command, globals, locals, filename=None) This function is similar to run(), with added arguments to supply the globals and locals dictionaries for the command string.

Profiling Ruby Code

To really drill into your code try out stackprof. Here’s a quick solution on how to use it: Install the gem: gem install stackprof. In your code add: require ‘stackprof’ and surround the part that you want to check with this: StackProf.run(mode: :cpu, out: ‘stackprof-output.dump’) do {YOUR_CODE} end After running your ruby script go check … Read more

High resolution timer in .NET

Here is a sample bit of code to time an operation: Dim sw As New Stopwatch() sw.Start() //Insert Code To Time sw.Stop() Dim ms As Long = sw.ElapsedMilliseconds Console.WriteLine(“Total Seconds Elapsed: ” & ms / 1000) EDIT: And the neat thing is that it can resume as well. Stopwatch sw = new Stopwatch(); foreach(MyStuff stuff … Read more

saving cProfile results to readable external file

Updated. You can get output of profiler using io.StringIO() and save it into file. Here is an example: import cProfile import pstats import io def my_func(): result = [] for i in range(10000): result.append(i) return result pr = cProfile.Profile() pr.enable() my_result = my_func() pr.disable() s = io.StringIO() ps = pstats.Stats(pr, stream=s).sort_stats(‘tottime’) ps.print_stats() with open(‘test.txt’, ‘w+’) … Read more

How to profile python 3.5 code line by line in jupyter notebook 5

You can use line_profiler in jupyter notebook. Install it: pip install line_profiler Within your jupyter notebook, call: %load_ext line_profiler Define your function prof_function as in your example. Finally, profile as follows: %lprun -f prof_function prof_function() Which will provide the output: Timer unit: 1e-06 s Total time: 3e-06 s File: <ipython-input-22-41854af628da> Function: prof_function at line 1 … Read more