Skip to content

Instantly share code, notes, and snippets.

@manofstick
Created July 4, 2018 09:17
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/04ba0c70c398bf5edeaba9b17d0b17c5 to your computer and use it in GitHub Desktop.
Save manofstick/04ba0c70c398bf5edeaba9b17d0b17c5 to your computer and use it in GitHub Desktop.
549 comp 2
module Program
open System.Diagnostics
open Perf
type Key1 =
struct
val A : int
new (a)= { A = a }
end
type Key2 =
struct
val A : int
val B : int
new (a,b)= { A=a;B=b }
end
type Key3 =
struct
val A : int
val B : int
val C : int
new (a,b,c)= { A=a;B=b;C=c }
end
type Key4 =
struct
val A : int
val B : int
val C : int
val D : int
new (a,b,c,d)= { A=a;B=b;C=c;D=d }
end
type Key5 =
struct
val A : int
val B : int
val C : int
val D : int
val E : int
new (a,b,c,d,e)= { A=a;B=b;C=c;D=d;E=e }
end
let mapTest n createKey =
let sw = Stopwatch.StartNew ()
let count =
Array.init n (fun n -> createKey n, n)
|> Map
|> fun d -> d.Count
count, sw.ElapsedMilliseconds
let createKey2 n = Key2(n%11,n%7)
let createKey3 n = Key3(n%11,n%7,n%5)
let createKey4 n = Key4(n%11,n%7,n%5,n%3)
let createKey5 n = Key5(n%11,n%7,n%5,n%3,n%2)
let createDictKey2 n = Key2(n,n)
let createDictKey3 n = Key3(n,n,n)
let createDictKey4 n = Key4(n,n,n,n)
let createDictKey5 n = Key5(n,n,n,n,n)
let runMapTest () =
let size = 100000
let mutable totalTime = 0L
for i = 1 to 5 do
let c2, t2 = mapTest size createDictKey2
let c3, t3 = mapTest size createDictKey3
let c4, t4 = mapTest size createDictKey4
let c5, t5 = mapTest size createDictKey5
totalTime <- totalTime + t2 + t3 + t4 + t5
printfn "mapTest %d,%d,%d,%d (%d,%d,%d,%d)" t2 t3 t4 t5 c2 c3 c4 c5
printfn "mapTest totalTime=%d" totalTime
[<EntryPoint>]
let main _ =
printfn "%s" Id.Name
runMapTest ()
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment