Skip to content

Instantly share code, notes, and snippets.

@ReedCopsey
Created August 23, 2014 00:27
Show Gist options
  • Save ReedCopsey/4a72a4fce61bd72e6b52 to your computer and use it in GitHub Desktop.
Save ReedCopsey/4a72a4fce61bd72e6b52 to your computer and use it in GitHub Desktop.
Timing on Seq.toArray with ICollection<'T> input
// Learn more about F# at http://fsharp.net
// See the 'F# Tutorial' project for more help.
open System.Diagnostics
[<EntryPoint>]
let main argv =
let sequ = seq [ 1 .. 10000000 ]
let cach = ResizeArray<_>(sequ)
let doTimings s =
let sw = Stopwatch.StartNew()
let arraySecond = cach |> Seq.toArray
sw.Stop()
float(arraySecond.Length), float(sw.ElapsedTicks)
printfn "pre-running for JIT"
let arrayFirst = cach |> Seq.toArray
let init = doTimings cach
let iterations = [1..10]
printfn "starting iterations"
let results = iterations |> List.map (fun _ -> doTimings cach)
let averageLength = results |> List.averageBy (fun l -> fst(l))
let averageTime = results |> List.averageBy (fun l -> snd(l))
printfn "Length %d=%f in %f ticks" arrayFirst.Length averageLength averageTime
0 // return an integer exit code
@latkin
Copy link

latkin commented Oct 21, 2014

Thanks for providing perf test code with your PR, makes it very easy to confirm behavior change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment