Skip to content

Instantly share code, notes, and snippets.

@manofstick
Created July 4, 2018 09:47
Show Gist options
  • Save manofstick/258edf7e7d39a76e9d1cdf0316ae2b47 to your computer and use it in GitHub Desktop.
Save manofstick/258edf7e7d39a76e9d1cdf0316ae2b47 to your computer and use it in GitHub Desktop.
module Program
open Perf
open System
open System.Diagnostics
open System.Collections.Generic
type StructureInt =
struct
val A : int
val B : int
new(a, b) = {
A = a
B = b
}
end
type StructureGeneric<'a,'b> =
struct
val A : 'a
val B : 'b
new(a, b) = {
A = a
B = b
}
end
let mutable r = Random ()
let a createRandomObj =
let mutable set = Set.empty
let mutable count = 0
let sw = Stopwatch.StartNew()
for i = 0 to 200000 do
set <- set.Add (createRandomObj ())
for i = 0 to 10 do
count <- count + if set.Contains (createRandomObj ()) then 1 else 0
printfn "%A (%A)" sw.ElapsedMilliseconds count
[<EntryPoint>]
let main argv =
printfn "%s" Id.Name
r <- Random 314159265
let sw = Stopwatch.StartNew ()
for i = 0 to 9 do
a (fun () -> StructureInt (r.Next 250, r.Next 250))
printfn "=> %d" sw.ElapsedMilliseconds
printfn "-------"
r <- Random 314159265
let sw = Stopwatch.StartNew ()
for i = 0 to 10 do
a (fun () -> StructureGeneric (r.Next 250, r.Next 250))
printfn "=> %d" sw.ElapsedMilliseconds
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment