Skip to content

Instantly share code, notes, and snippets.

@braden
Created April 4, 2015 17:02
Show Gist options
  • Save braden/8b75e39b625586c779a1 to your computer and use it in GitHub Desktop.
Save braden/8b75e39b625586c779a1 to your computer and use it in GitHub Desktop.
Array.empty benchmark
#time
(*
Without optimization
Real: 00:00:00.765, CPU: 00:00:00.765, GC gen0: 763, gen1: 1, gen2: 0
Real: 00:00:00.781, CPU: 00:00:00.765, GC gen0: 763, gen1: 0, gen2: 0
Real: 00:00:00.767, CPU: 00:00:00.765, GC gen0: 762, gen1: 0, gen2: 0
With optimization
Real: 00:00:00.721, CPU: 00:00:00.734, GC gen0: 477, gen1: 1, gen2: 0
Real: 00:00:00.723, CPU: 00:00:00.718, GC gen0: 477, gen1: 0, gen2: 0
Real: 00:00:00.734, CPU: 00:00:00.734, GC gen0: 477, gen1: 0, gen2: 0
*)
let getArray i =
match i % 2 with
| 0 -> [||]
| _ -> [| 1;2;3|]
let test n =
let mutable sum = 0
for i = 0 to n do
sum <- sum + (getArray i).Length
sum
printfn "Sum: %i" (test 100000000);;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment