Skip to content

Instantly share code, notes, and snippets.

Created March 17, 2016 19:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
let time countN label f =
let stopwatch = System.Diagnostics.Stopwatch()
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()
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