This is an amended excerpt from Scott Wlaschin: https://gist.github.com/swlaschin/348b6b9e64d4b150cf86#file-typesafe-performance-with-compiler-directives-5-fsx-L224
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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