Guest User

Untitled

a guest
Jul 23rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. open System
  2. open System.Diagnostics
  3. open System
  4.  
  5. let getNextSequential n =
  6. let r = Random 42
  7. let start = r.Next (n*3/2)
  8. fun i -> (start + i) % n
  9.  
  10. let getNextRandom n =
  11. let r = Random 42
  12. fun _ -> r.Next (n*4)
  13.  
  14. [<EntryPoint>]
  15. let main argv =
  16. let f =
  17. match argv with
  18. | [| "sequential" |] -> getNextSequential
  19. | [| "random" |] -> getNextRandom
  20. | _ -> failwith "invalid arg"
  21.  
  22. for i in 0 .. 25 .. 250 do
  23. let getNext = f i
  24.  
  25. let elementsA = Array.init i getNext
  26. let elementsB = Array.init i getNext
  27.  
  28. let sw = Stopwatch.StartNew ()
  29. for j = 1 to 1000000 / (i+1) do
  30. let a = Set.ofArray elementsA
  31. let b = Set.ofArray elementsB
  32. let c = Set.union a b
  33. for a in elementsA do
  34. if not (c |> Set.contains a) then failwith "boom"
  35. for b in elementsB do
  36. if not (c |> Set.contains b) then failwith "boom"
  37.  
  38. printfn "%s,%s,%d,%d" argv.[0] (if Environment.Is64BitProcess then "64-bit" else "32-bit") i sw.ElapsedMilliseconds
  39.  
  40. 0 // return an integer exit code
Add Comment
Please, Sign In to add comment