Created
August 23, 2014 00:27
-
-
Save ReedCopsey/4a72a4fce61bd72e6b52 to your computer and use it in GitHub Desktop.
Timing on Seq.toArray with ICollection<'T> input
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
// 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for providing perf test code with your PR, makes it very easy to confirm behavior change.