Skip to content

Instantly share code, notes, and snippets.

@manofstick
Created Jul 23, 2018
Embed
What would you like to do?
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