Last active
August 29, 2015 14:17
-
-
Save leeavital/b47fa1edd19434f9fc17 to your computer and use it in GitHub Desktop.
Benchmark
This file contains hidden or 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
#!/bin/bash | |
old=old.out | |
new=new.out | |
echo "" > tmp | |
echo "" > out.csv | |
for i in $(seq 10000 100 50000) | |
do | |
echo $i | |
echo "$i" > tmp | |
/usr/bin/time --format "%e" ./old.out $i 1> /dev/null 2>> tmp | |
/usr/bin/time --format "%e" ./new.out $i 1> /dev/null 2>> tmp | |
cat tmp | tr "\n" "," >> out.csv | |
echo "" >> out.csv | |
# /usr/bin/time --format "%e" ./new.out $i > /dev/null | tr -d '\n' &>> out.csv | |
done |
This file contains hidden or 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
fun naiveIsPrime n = | |
let | |
fun helper n agg = | |
if agg = 1 then | |
true | |
else if n mod agg = 0 then | |
false | |
else | |
helper n (agg - 1) | |
in | |
helper n (n-1) | |
end | |
fun naivePrims n = | |
let fun helper n x = | |
if n = 0 then | |
[] | |
else if (naiveIsPrime x) then | |
x::(helper (n-1) (x+1)) | |
else | |
helper (n-1) (x+1) | |
in | |
helper n 2 | |
end | |
exception NoArgs | |
val n = case CommandLine.arguments () of | |
(x::nil) => Option.valOf (Int.fromString(x)) | |
| _ => raise NoArgs | |
val ns = naivePrims n | |
val _ = List.app (print o (fn x => x ^ ",") o Int.toString) ns |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment