Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Standardize benchmark names, and output format.

Set up things so that they can go into CSV files, and into spreadsheets etc.
Times are now printed in milliseconds.
  • Loading branch information...
commit 1e77ad822deecd635f99fc7408c66a894582812a 1 parent 579a67c
@ViralBShah ViralBShah authored
Showing with 46 additions and 59 deletions.
  1. +14 −11 test/perf.cc
  2. +7 −11 test/perf.j
  3. +16 −29 test/perf.m
  4. +9 −8 test/perf.py
View
25 test/perf.cc
@@ -35,7 +35,7 @@ int fib(int n) {
long parse_int(const char *s, long base) {
long n = 0;
- for (int i=0; i<strlen(s); ++i) {
+ for (unsigned int i=0; i<strlen(s); ++i) {
char c = s[i];
long d = 0;
if (c >= '0' && c <= '9') d = c-'0';
@@ -135,9 +135,12 @@ double pisum() {
return sum;
}
-int main() {
- printf("**** C ****\n");
+void print_perf(const char *name, double t) {
+ printf("c, %15s, %.6f\n", name, t*1000);
+}
+
+int main() {
// Initialize RNG
dsfmt_gv_init_gen_rand(0);
@@ -151,18 +154,18 @@ int main() {
f += fib(20);
}
t2 = CLOCK() - t1;
- printf("fib(20):\t %1.8lf\n", (t2/(double)NITER));
+ print_perf("fib", (t2/(double)NITER));
// parse_bin
assert(parse_int("1111000011110000111100001111", 2) == 252645135);
t1 = CLOCK();
for (int i=0; i<NITER; ++i) {
for (int k=0; k<1000; ++k) {
- long n = parse_int("1111000011110000111100001111", 2);
+ parse_int("1111000011110000111100001111", 2);
}
}
t2 = CLOCK() - t1;
- printf("parse_bin:\t %1.8lf\n", (t2/(double)NITER));
+ print_perf("parse_int", (t2/(double)NITER));
// array constructor
t1 = CLOCK();
@@ -171,7 +174,7 @@ int main() {
free(a);
}
t2 = CLOCK() - t1;
- printf("ones(200,200):\t %1.8lf\n", (t2/NITER));
+ print_perf("ones", (t2/NITER));
// A*A'
//SUBROUTINE DGEMM(TRANSA,TRANSB,M,N,K,ALPHA,A,LDA,B,LDB,BETA,C,LDC)
@@ -183,7 +186,7 @@ int main() {
}
t2 = CLOCK() - t1;
free(b);
- printf("A*A': \t %1.8lf\n", (t2/NITER));
+ print_perf("AtA", (t2/NITER));
// mandel
int mandel_sum;
@@ -193,7 +196,7 @@ int main() {
}
assert(mandel_sum == 14720);
t2 = CLOCK() - t1;
- printf("mandel: \t %1.8lf\n", (t2/NITER));
+ print_perf("mandel", (t2/NITER));
// sort
t1 = CLOCK();
@@ -203,7 +206,7 @@ int main() {
free(d);
}
t2 = CLOCK() - t1;
- printf("sort: \t %1.8lf\n", (t2/NITER));
+ print_perf("quicksort", (t2/NITER));
// pi sum
t1 = CLOCK();
@@ -213,7 +216,7 @@ int main() {
}
assert(fabs(pi-1.644834071848065) < 1e-12);
t2 = CLOCK() - t1;
- printf("pisum: \t %1.8lf\n", (t2/NITER));
+ print_perf("pi_sum", (t2/NITER));
return 0;
}
View
18 test/perf.j
@@ -1,14 +1,10 @@
-println("*** Julia ***")
-
-# simple performance tests
-
macro timeit(ex,name)
quote
t = Inf
for i=1:5
t = min(t, @elapsed $ex)
end
- println(rpad(strcat($name,":"), 20), t)
+ println("julia, ", rpad(strcat($name,","), 15), t*1000)
end
end
@@ -17,7 +13,7 @@ end
fib(n) = n < 2 ? n : fib(n-1) + fib(n-2)
@assert fib(20) == 6765
-@timeit fib(20) "recursive fib"
+@timeit fib(20) "fib"
## parse int ##
@@ -41,7 +37,7 @@ end
A = ones(200,200)
@assert A*A' == 200
-@timeit A*A' "A*A'"
+@timeit A*A' "AtA"
## mandelbrot set: complex arithmetic and comprehensions ##
@@ -60,7 +56,7 @@ end
mandelperf() = [ mandel(complex(r,i)) | r=-2.0:.1:0.5, i=-1.:.1:1. ]
@assert sum(mandelperf()) == 14791
-@timeit mandelperf() "mandelbrot"
+@timeit mandelperf() "mandel"
## numeric vector sort ##
@@ -69,7 +65,7 @@ function sortperf(n)
v = sort(v)
end
@assert issorted(sortperf(5000))
-@timeit sortperf(5000) "sort"
+@timeit sortperf(5000) "quicksort"
## slow pi series ##
@@ -85,7 +81,7 @@ function pisum()
end
@assert abs(pisum()-1.644834071848065) < 1e-12
-@timeit pisum() "pi sum"
+@timeit pisum() "pi_sum"
## Random matrix statistics ##
@@ -108,4 +104,4 @@ end
(s1, s2) = randmatstat(1000)
@assert s1 > 0.5 && s1 < 1.0
-@timeit randmatstat(1000) "random matrix"
+@timeit randmatstat(1000) "rand_mat_stat"
View
45 test/perf.m
@@ -1,9 +1,4 @@
function perf()
-% simple performance tests
-
-function nl()
- fprintf('\n')
-end
function assert(expr)
if ~expr
@@ -11,7 +6,12 @@ function assert(expr)
end
end
-function timeit(func, varargin)
+function timeit(name, func, varargin)
+ lang = 'matlab';
+ if exist('OCTAVE_VERSION') ~= 0
+ lang = 'octave';
+ end
+
nexpt = 5;
times = zeros(nexpt, 1);
@@ -20,14 +20,9 @@ function timeit(func, varargin)
end
times = sort(times);
- fprintf ('%.8f', times(1));
- nl()
- nl()
+ fprintf ('%s, %15s, %.8f\n', lang, name, times(1)*1000);
end
-nl()
-
-fprintf ('*** Matlab/Octave ***\n')
%% recursive fib %%
@@ -40,14 +35,12 @@ function timeit(func, varargin)
end
end
-fprintf('recursive fib(20): ')
f = fib(20);
assert(f == 6765)
-timeit(@fib, 20)
+timeit('fib', @fib, 20)
%% parse int %%
-fprintf('parse_int: ')
bin2dec('10');
function n = parseintperf(ignore)
for i=1:1000
@@ -55,23 +48,21 @@ function timeit(func, varargin)
end
end
assert(parseintperf(true) == 252645135)
-timeit(@parseintperf, true)
+timeit('parse_int', @parseintperf, true)
%% array constructors %%
-fprintf('ones: ')
o = ones(200,200);
assert(all(o) == 1)
-timeit(@ones, 200, 200)
+timeit('ones', @ones, 200, 200)
%% matmul and transpose %%
-fprintf('A * transpose(A): ');
function oo = matmul(o)
oo = o * o.';
end
assert(all(matmul(o) == 200))
-timeit(@matmul, o)
+timeit('AtA', @matmul, o)
%% mandelbrot set: complex arithmetic and comprehensions %%
@@ -86,7 +77,6 @@ function timeit(func, varargin)
end
end
-fprintf('mandelbrot: ');
mandel(complex(-.53,.68));
function M = mandelperf(ignore)
@@ -100,7 +90,7 @@ function timeit(func, varargin)
end
end
assert(sum(sum(mandelperf(true))) == 14628)
-timeit (@mandelperf, true)
+timeit ('mandel', @mandelperf, true)
%% numeric vector quicksort %%
@@ -132,14 +122,13 @@ function timeit(func, varargin)
end
end
-fprintf('quicksort: ')
function v = sortperf(n)
v = rand(n,1);
v = qsort_kernel(v,1,n);
%v = sort(v);
end
assert(issorted(sortperf(5000)))
-timeit (@sortperf, 5000)
+timeit ('quicksort', @sortperf, 5000)
%% slow pi series %%
@@ -153,10 +142,9 @@ function timeit(func, varargin)
end
end
-fprintf('pi sum: ')
s = pisum(true);
assert(abs(s-1.644834071848065) < 1e-12);
-timeit(@pisum, true)
+timeit('pi_sum',@pisum, true)
function [s1, s2] = randmatstat(t)
n=5;
@@ -176,10 +164,9 @@ function timeit(func, varargin)
s2 = std(w)/mean(w);
end
-fprintf('random matrix statistics: ');
[s1, s2] = randmatstat(1000);
-assert(round(10*s1) > 6 && round(10*s1) < 8);
-timeit (@randmatstat, 1000)
+assert(round(10*s1) > 5 && round(10*s1) < 10);
+timeit ('rand_mat_stat', @randmatstat, 1000)
function t = mytranspose(x)
[m, n] = size(x);
View
17 test/perf.py
@@ -107,40 +107,41 @@ def pisum():
sum += 1.0/(k*k)
return sum
+def print_perf(name, time):
+ print "python, ", name, ", ", time*1000
+
## run tests ##
if __name__=="__main__":
- print "**** Python ****\n"
-
assert fib(20) == 6765
t = time.time()
f = fib(20)
- print "fib: ", time.time()-t
+ print_perf("fib", time.time()-t)
assert int("1111000011110000111100001111",2) == 252645135
t = time.time()
for i in xrange(1,1000):
int("1111000011110000111100001111",2)
- print "parse_int: ", time.time()-t
+ print_perf ("parse_int", time.time()-t)
assert sum(mandelperf()) == 14304
t = time.time()
mandelperf()
- print "mandelbrot: ", time.time()-t
+ print_perf ("mandel", time.time()-t)
lst = [ random.random() for i in xrange(1,5000) ]
t = time.time()
quicksort(lst, 0, len(lst)-1)
- print "sort: ", time.time()-t
+ print_perf ("quicksort", time.time()-t)
pi = pisum()
assert abs(pisum()-1.644834071848065) < 1e-6
t = time.time()
pisum()
- print "pisum: ", time.time()-t
+ print_perf ("pi_sum", time.time()-t)
(s1, s2) = randmatstat(1000)
assert s1 > 0.5 and s1 < 1.0
t = time.time()
randmatstat(1000)
- print "random matrix: ", time.time()-t
+ print_perf ("rand_mat_stat", time.time()-t)
Please sign in to comment.
Something went wrong with that request. Please try again.