Skip to content

Instantly share code, notes, and snippets.

@manofstick
Created July 31, 2015 10:02
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/1b7cce949487c32b3fea to your computer and use it in GitHub Desktop.
Save manofstick/1b7cce949487c32b3fea to your computer and use it in GitHub Desktop.
Showing the initial "priming" time, and tuples
open System
open System.Diagnostics
let check<'a when 'a : equality>(x:'a, y:'a) =
for i=1 to 0 do failwith "this is just to stop f# inlining"
if x = y then 1 else 0
let count = 50000000
let tuple2 () =
let sw = Stopwatch.StartNew ()
if check ((1,1), (1,1)) = 1 then printf "priming="
printfn "%dms" sw.ElapsedMilliseconds
let x = int (sqrt (float count))
let y = count / x
printfn "count=%d" (x * y)
let sw = Stopwatch.StartNew ()
let mutable count = 0
for i = 1 to x do
for j = 1 to y do
count <- count + check ((i,j), (j,i))
printfn "processing=%d (%d)" sw.ElapsedMilliseconds count
let tuple3 () =
let sw = Stopwatch.StartNew ()
if check ((1,1,1), (1,1,1)) = 1 then printf "priming="
printfn "%dms" sw.ElapsedMilliseconds
let x = int ((float count) ** (1.0/3.0))
let y = x
let z = count / (x * y)
printfn "count=%d" (x * y * z)
let sw = Stopwatch.StartNew ()
let mutable count = 0
for i = 1 to x do
for j = 1 to y do
for k = 1 to z do
count <- count + check ((i,j,k), (k,j,i))
printfn "processing=%d (%d)" sw.ElapsedMilliseconds count
let tuple4 () =
let sw = Stopwatch.StartNew ()
if check ((1,1,1,1), (1,1,1,1)) = 1 then printf "priming="
printfn "%dms" sw.ElapsedMilliseconds
let w = int ((float count) ** (1.0/4.0))
let x = w
let y = w
let z = count / (w * x * y)
printfn "count=%d" (x * w * y * z)
let sw = Stopwatch.StartNew ()
let mutable count = 0
for i = 1 to x do
for j = 1 to y do
for k = 1 to z do
for l = 1 to z do
count <- count + check ((i,j,k,l), (l,k,j,i))
printfn "processing=%d (%d)" sw.ElapsedMilliseconds count
[<EntryPoint>]
let main _ =
printfn "%s" Id.Name
tuple2 ()
tuple3 ()
tuple4 ()
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment