Guest User

Untitled

a guest
Jan 21st, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. open System.Diagnostics
  2.  
  3. let n = 1000000
  4. let a = Array.init n id
  5.  
  6. let measure f s =
  7. let sw = new Stopwatch();
  8. sw.Start()
  9. let r = f()
  10. sw.Stop()
  11. printfn s r (sw.Elapsed)
  12. ()
  13.  
  14. let test reader =
  15. Seq.fold (fun acc i -> if i % 2 = 0 then acc + reader i else acc - reader i) 0 { 0 .. n - 1 }
  16.  
  17. measure (fun () -> test (fun i -> a.[i])) "read1: %A [%O]"
  18. measure (fun () -> test (Array.get a)) "read2: %A [%O]"
Add Comment
Please, Sign In to add comment