Skip to content

Instantly share code, notes, and snippets.

@monkieboy
Created March 17, 2016 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monkieboy/36b312c42e9fe6447cd0 to your computer and use it in GitHub Desktop.
Save monkieboy/36b312c42e9fe6447cd0 to your computer and use it in GitHub Desktop.
let time countN label f =
let stopwatch = System.Diagnostics.Stopwatch()
System.GC.Collect()
printfn "Started"
let getGcStats() =
let gen0 = System.GC.CollectionCount(0)
let gen1 = System.GC.CollectionCount(1)
let gen2 = System.GC.CollectionCount(2)
let mem = System.GC.GetTotalMemory(false)
gen0, gen1, gen2, mem
printfn "========================"
printfn "%s" label
printfn "========================"
for iteration in [1..countN] do
let gen0, gen1, gen2, mem = getGcStats()
stopwatch.Restart()
f()
stopwatch.Stop()
let gen0', gen1', gen2', mem' = getGcStats()
let changeInMem = (mem'-mem)/1000L
printfn "#%2i elapsed:%6ims gen0:%3i gen1:%3i gen2:%3i mem:%6iK" iteration stopwatch.ElapsedMilliseconds (gen0'-gen0) (gen1'-gen1) (gen2'-gen2) changeInMem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment