Guest User

Untitled

a guest
Feb 16th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. let () =
  2. let x = !(ref 2) in
  3. let y = !(ref 3) in
  4. let z = !(ref (-4)) in
  5. assert (x + y = 5);
  6. assert (x + z = -2);
  7. assert (z + y = -1);
  8. assert (x + y + z = 1);
  9. assert (x - y = -1);
  10. assert (x - z = 6);
  11. assert (z - y = -7);
  12. assert (x + y - z = 9);
  13. assert (x - y + z = -5);
  14. assert (x - y - z = 3);
  15.  
  16. let start = Unix.gettimeofday () in
  17. let rec loop x y =
  18. let x = x - y in
  19. let x = x - y in
  20. let x = x - y in
  21. let x = x - y in
  22. let x = x - y in
  23. let x = x - y in
  24. let x = x - y in
  25. let x = x - y in
  26. if x < 1000000000 then
  27. loop x y
  28. in
  29. loop 1 (-1);
  30. Printf.printf "%f\n" (Unix.gettimeofday () -. start);
  31.  
  32. let start = Unix.gettimeofday () in
  33. let rec loop x y =
  34. let x = x + y in
  35. let x = x + y in
  36. let x = x + y in
  37. let x = x + y in
  38. let x = x + y in
  39. let x = x + y in
  40. let x = x + y in
  41. let x = x + y in
  42.  
  43. if x < 1000000000 then
  44. loop x y
  45. in
  46. loop 1 1;
  47. Printf.printf "%f\n" (Unix.gettimeofday () -. start)
Add Comment
Please, Sign In to add comment