Created
March 9, 2014 14:48
-
-
Save zakki/9448891 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let f a = | |
let t0 = Unix.gettimeofday() in | |
let acc = ref a in | |
for j = 1 to 10000000 do | |
acc := !acc +. (float_of_int j) | |
done; | |
let t1 = Unix.gettimeofday() in | |
Printf.printf "Time: %.3f %f\n%!" (t1-.t0) !acc | |
let _ = | |
for i = 0 to 3 do | |
f 0.; | |
f 1.; | |
f nan; | |
f infinity | |
done | |
(* | |
:$ time ./a.out | |
Time: 0.035 50000005000000.000000 | |
Time: 0.031 50000005000001.000000 | |
Time: 1.513 nan | |
Time: 1.596 inf | |
Time: 0.035 50000005000000.000000 | |
Time: 0.038 50000005000001.000000 | |
Time: 1.602 nan | |
Time: 1.477 inf | |
Time: 0.030 50000005000000.000000 | |
Time: 0.034 50000005000001.000000 | |
Time: 1.624 nan | |
Time: 1.723 inf | |
Time: 0.031 50000005000000.000000 | |
Time: 0.031 50000005000001.000000 | |
Time: 1.545 nan | |
Time: 1.473 inf | |
*) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment