3 people like it.

One-liner generic timing function

Generic higher-order function to measure timing of a given function

1: 
let time f x = System.Diagnostics.Stopwatch.StartNew() |> (fun sw -> (f x, sw.Elapsed))
val time : f:('a -> 'b) -> x:'a -> 'b * System.TimeSpan

Full name: Script.time
val f : ('a -> 'b)
val x : 'a
namespace System
namespace System.Diagnostics
Multiple items
type Stopwatch =
  new : unit -> Stopwatch
  member Elapsed : TimeSpan
  member ElapsedMilliseconds : int64
  member ElapsedTicks : int64
  member IsRunning : bool
  member Reset : unit -> unit
  member Restart : unit -> unit
  member Start : unit -> unit
  member Stop : unit -> unit
  static val Frequency : int64
  ...

Full name: System.Diagnostics.Stopwatch

--------------------
System.Diagnostics.Stopwatch() : unit
System.Diagnostics.Stopwatch.StartNew() : System.Diagnostics.Stopwatch
val sw : System.Diagnostics.Stopwatch
property System.Diagnostics.Stopwatch.Elapsed: System.TimeSpan
Raw view Test code New version

More information

Link:http://fssnip.net/iW
Posted:11 years ago
Author:Lincoln Atkinson
Tags: one-liner , timing