Created
October 23, 2015 13:35
-
-
Save dsyme/8a0d3edfb31217dfa927 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
let inline min (array:_[]) = | |
let mutable acc = array.[0] | |
for i = 1 to array.Length - 1 do | |
let curr = array.[i] | |
if curr < acc then | |
acc <- curr | |
acc | |
let min2 (array:_[]) = | |
let mutable acc = array.[0] | |
for i = 1 to array.Length - 1 do | |
let curr = array.[i] | |
if curr < acc then | |
acc <- curr | |
acc | |
let min3 (array:int[]) = | |
let mutable acc = array.[0] | |
for i = 1 to array.Length - 1 do | |
let curr = array.[i] | |
if FSharp.Core.Operators.NonStructuralComparison.(<) curr acc then | |
acc <- curr | |
acc | |
#time "on" | |
let arr = Array.init 1000000 id | |
for i in 0 .. 100 do Array.min arr |> ignore // 0.27 seconds | |
for i in 0 .. 100 do min arr |> ignore // 0.27 seconds | |
for i in 0 .. 100 do min2 arr |> ignore // 13.7 seconds | |
for i in 0 .. 100 do min3 arr |> ignore // 0.234 seconds but not generic |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment