F# Interactive (and in general REPL-style tools) is an ideal entrance to performance profiling. What could be easier than to select a code block and send it right to a profiler that would come back with performance analysis report. Unfortunately it looks like existing profilers don't have REPL support: you have to either attach a profiler to a process or specify and executable or Web application to profile.
What I end up doing then is wrapping a code block to profile in a unit test and then executing a profile against NUnit command-line session. But is this the best we can do right now with F#?
What is the question?
Do you know about the #time
command? E.g.
#time "on"
for i in 1..1000000 do
let r = f(i)
ignore r
which gives F# interactive output like
--> Timing now on
Real: 00:00:00.000, CPU: 00:00:00.000, GC gen0: 0, gen1: 0, gen2: 0
In any case, I think simply putting the code in an application and running the profile against the app is better than an NUnit test. Either way, yes, it costs you maybe an extra 30 seconds of time to paste the code into a new app and compile it in Release mode. But that's a price I'm happy to pay to get the rich profiling info that Visual Studio provides. Ideally the experience could be better, but I doubt you'll find any REPL-friendly profiling tools today (or tomorrow).
You can try to use profiler programmatic API to achieve this. I have not tried this, but here are the instruction for ANTS profiler: http://help.red-gate.com/help/ANTSProfiler3/0/en/Topics/AP_UsingTheAPI.html
I think the following might succeed:
DotTrace has (had?) similiar API (CPUProfiler.Start()/.StopAndTakeSnapshot()), but I could not find the references for latest versions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With