Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to measure CPU and memory usage of F# code?

I'm new to the language F# and currently I'm doing a short study on the F# performance. So what I would like to do is benchmark my F# code. I've already found the Stopwatch class, which was pretty obvious, but as for the rest of what you should be able to test, I found no clear leads.

What I would wish to do is to find out memory and cpu usage of the F# code when I run it. Is there anyone here that might be able to give me some advices on how to do this?

like image 364
Marcus Åberg Avatar asked Apr 06 '12 15:04

Marcus Åberg


People also ask

How do I check my CPU and RAM usage?

Press CTRL + Shift + Esc to open Task Manager. Click the Performance tab. This tab displays your system's RAM, CPU, GPU, and disk usage, along with network info. To view RAM usage, select the Memory box.

How do you measure CPU usage?

To get CPU usage, periodically sample the total process time, and find the difference. You subtract the kernel times (for a difference of 0.03 ) and the user times ( 0.61 ), add them together ( 0.64 ), and divide by the sample time of 2 seconds ( 0.32 ).


1 Answers

For quick prototyping, fsi's timing directive provides good indications:

#if INTERACTIVE
#time "on"
#endif

It prints out something like:

Real: 00:00:00.199, CPU: 00:00:00.120, GC gen0: 0, gen1: 0, gen2: 0 

Beside execution time, other statistics show amounts of garbage collected in three levels of the generational GC, which are helpful to understand memory usage in your programs.

For serious benchmarking, you should use Visual Studio profiler which provides function call counts, timing, and memory allocation measurement, etc or even use third-party memory profilers. You can find some hints of using these profilers in my answer at Good F# Performance Profiling Tool.

like image 125
pad Avatar answered Sep 21 '22 16:09

pad