Skip to content

Instantly share code, notes, and snippets.

@dsyme
Created October 23, 2015 13:35
Show Gist options
  • Save dsyme/8a0d3edfb31217dfa927 to your computer and use it in GitHub Desktop.
Save dsyme/8a0d3edfb31217dfa927 to your computer and use it in GitHub Desktop.
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