Skip to content

Instantly share code, notes, and snippets.

@manofstick
Created July 23, 2018 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manofstick/b25efcf69fb7791357918d5a780ac438 to your computer and use it in GitHub Desktop.
Save manofstick/b25efcf69fb7791357918d5a780ac438 to your computer and use it in GitHub Desktop.
open System
open System.Diagnostics
open System
let getNextSequential n =
let r = Random 42
let start = r.Next (n*3/2)
fun i -> (start + i) % n
let getNextRandom n =
let r = Random 42
fun _ -> r.Next (n*4)
[<EntryPoint>]
let main argv =
let f =
match argv with
| [| "sequential" |] -> getNextSequential
| [| "random" |] -> getNextRandom
| _ -> failwith "invalid arg"
for i in 0 .. 25 .. 250 do
let getNext = f i
let elementsA = Array.init i getNext
let elementsB = Array.init i getNext
let sw = Stopwatch.StartNew ()
for j = 1 to 1000000 / (i+1) do
let a = Set.ofArray elementsA
let b = Set.ofArray elementsB
let c = Set.union a b
for a in elementsA do
if not (c |> Set.contains a) then failwith "boom"
for b in elementsB do
if not (c |> Set.contains b) then failwith "boom"
printfn "%s,%s,%d,%d" argv.[0] (if Environment.Is64BitProcess then "64-bit" else "32-bit") i sw.ElapsedMilliseconds
0 // return an integer exit code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment