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

f#, measurement, performance

Solution

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.

Problem

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?

Original source

Related problems