Skip to content

Instantly share code, notes, and snippets.

@monkieboy
Created Mar 17, 2016
Embed
What would you like to do?
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