Created
November 20, 2018 19:17
-
-
Save topnotch48/c0c7de1e7b75d789a3d6a2ba0975f395 to your computer and use it in GitHub Desktop.
a simple profiling function for f#, measures both real and cpu timings.
This file contains hidden or 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
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