Skip to content

Instantly share code, notes, and snippets.

@cameronpresley
Created February 8, 2016 18:43
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 cameronpresley/eddd0b074d9840aa486b to your computer and use it in GitHub Desktop.
Save cameronpresley/eddd0b074d9840aa486b to your computer and use it in GitHub Desktop.
Performance Logger - Computational Expression that logs how long a function ran
open System.Diagnostics
open System.Threading
type PerformanceLogger (printer:string -> unit) =
member this.Bind(x, func) =
let stopWatch = new Stopwatch()
stopWatch.Start ()
func x
stopWatch.Stop ()
printer (sprintf "Took %i seconds to run %A" (stopWatch.ElapsedMilliseconds/1000L) (func))
member this.Zero () = ()
member this.Return x = x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment