Skip to content

Instantly share code, notes, and snippets.

@topnotch48
Created November 20, 2018 19:17
Show Gist options
  • Save topnotch48/c0c7de1e7b75d789a3d6a2ba0975f395 to your computer and use it in GitHub Desktop.
Save topnotch48/c0c7de1e7b75d789a3d6a2ba0975f395 to your computer and use it in GitHub Desktop.
a simple profiling function for f#, measures both real and cpu timings.
open System.Diagnostics
let time f =
let proc = Process.GetCurrentProcess()
let cpu_time_stamp = proc.TotalProcessorTime
let timer = new Stopwatch()
timer.Start()
try
f()
finally
let cpu_time = (proc.TotalProcessorTime-cpu_time_stamp).TotalMilliseconds
printfn "CPU time = %dms" (int64 cpu_time)
printfn "Absolute time = %dms" timer.ElapsedMilliseconds
let rec loop n f x =
if n > 0 then
f x |> ignore
loop (n-1) f x
time (fun () -> loop 1000000 List.sum [1..100])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment