diff --git a/examples/shootout/timing.jl b/examples/shootout/timing.jl deleted file mode 100644 index 96a3b0dd1c41a..0000000000000 --- a/examples/shootout/timing.jl +++ /dev/null @@ -1,12 +0,0 @@ -macro timeit(ex,name) - @gensym t i - quote - $t = Inf - for $i=1:5 - $t = min($t, @elapsed $ex) - end - @printf("julia, %s: best of 5 took %.1f ms\n", $name, $t*1000) - end -end - - diff --git a/test/Makefile b/test/Makefile index 972cd014ce702..b77e76aea596f 100644 --- a/test/Makefile +++ b/test/Makefile @@ -2,7 +2,7 @@ JULIAHOME = $(abspath ..) include ../Make.inc TESTS = all core keywordargs numbers strings unicode collections hashing \ - remote iostring arrayops linalg blas fft dsp sparse bitarray random \ + remote iostring arrayops linalg blas fft dsp sparse bitarray random \ math functional bigint sorting statistics spawn parallel arpack file \ git pkg pkg2 resolve resolve2 suitesparse complex version pollfd mpfr \ broadcast socket floatapprox priorityqueue readdlm regex @@ -11,20 +11,13 @@ $(TESTS) :: $(QUIET_JULIA) $(call spawn,$(JULIA_EXECUTABLE)) ./runtests.jl $@ perf: -ifneq ($(MAKECMDGOALS),perf) - $(QUIET_JULIA) $(call spawn,$(JULIA_EXECUTABLE)) perf/$@.jl -else - @$(call spawn,$(JULIA_EXECUTABLE)) perf/$@.jl | perl -nle '@_=split/,/; printf "%-14s %7.3f\n", $$_[1], $$_[2]' -endif - -benchmark: - @$(MAKE) -C perf $@ + @$(MAKE) -C perf all clean: @$(MAKE) -C perf $@ -rm -f libccalltest.${SHLIB_EXT} ccalltest -.PHONY: $(TESTS) perf benchmark clean +.PHONY: $(TESTS) perf clean libccalltest.$(SHLIB_EXT): ccalltest.c $(CC) $(CFLAGS) $(DEBUGFLAGS) -O3 $< -fPIC -shared -o $@ $(LDFLAGS) -DCC=$(CC) diff --git a/test/load/ltests.jl b/test/netload/ltests.jl similarity index 100% rename from test/load/ltests.jl rename to test/netload/ltests.jl diff --git a/test/load/memtest.jl b/test/netload/memtest.jl similarity index 100% rename from test/load/memtest.jl rename to test/netload/memtest.jl diff --git a/test/load/sockxfer.jl b/test/netload/sockxfer.jl similarity index 100% rename from test/load/sockxfer.jl rename to test/netload/sockxfer.jl diff --git a/test/perf.jl b/test/perf.jl deleted file mode 100644 index 096fa46f5a776..0000000000000 --- a/test/perf.jl +++ /dev/null @@ -1 +0,0 @@ -include("perf/perf.jl") diff --git a/test/perf/Makefile b/test/perf/Makefile index 98edb2bebcf9c..fad1e2792a645 100644 --- a/test/perf/Makefile +++ b/test/perf/Makefile @@ -1,94 +1,13 @@ -JULIAHOME = ../.. -include $(JULIAHOME)/Make.inc -include $(JULIAHOME)/deps/Versions.make +JULIAHOME = $(abspath ../..) +include ../../Make.inc -ifeq ($(OS), WINNT) -MATHEMATICABIN = MathKernel -else ifeq ($(OS), Darwin) -MATHEMATICABIN = MathKernel -else -MATHEMATICABIN = math -endif +all: micro kernel cat shootout -default: benchmarks.html - -export OMP_NUM_THREADS=1 -export GOTO_NUM_THREADS=1 -export OPENBLAS_NUM_THREADS=1 - -perf.h: $(JULIAHOME)/deps/Versions.make - echo '#include "$(JULIAHOME)/deps/openblas-$(OPENBLAS_VER)/cblas.h"' > $@ - echo '#include "$(JULIAHOME)/deps/random/dsfmt-$(DSFMT_VER)/dSFMT.c"' >> $@ - -bin/perf%: perf.c perf.h - $(CC) -std=c99 -O$* $< -o $@ $(JULIAHOME)/deps/openblas-$(OPENBLAS_VER)/libopenblas.a -lpthread - -bin/fperf%: perf.f90 - $(FC) -static-libgfortran -O$* -fexternal-blas $< -o $@ $(JULIAHOME)/deps/openblas-$(OPENBLAS_VER)/libopenblas.a -lpthread - -benchmarks/c.csv: \ - benchmarks/c0.csv \ - benchmarks/c1.csv \ - benchmarks/c2.csv \ - benchmarks/c3.csv - cat $^ > $@ - -benchmarks/fortran.csv: \ - benchmarks/fortran0.csv \ - benchmarks/fortran1.csv \ - benchmarks/fortran2.csv \ - benchmarks/fortran3.csv - cat $^ > $@ - -benchmarks/c%.csv: bin/perf% - for t in 1 2 3 4 5; do $<; done >$@ - -benchmarks/fortran%.csv: bin/fperf% - for t in 1 2 3 4 5; do $<; done >$@ - -benchmarks/go.csv: perf.go - for t in 1 2 3 4 5; do go run $<; done >$@ - -benchmarks/julia.csv: perf.jl - for t in 1 2 3 4 5; do ../../julia $<; done >$@ - -benchmarks/python.csv: perf.py - for t in 1 2 3 4 5; do python $<; done >$@ - -benchmarks/matlab.csv: perf.m - for t in 1 2 3 4 5; do matlab -nosplash -nodesktop -nojvm -r 'perf;exit' 2>/dev/null | grep '^matlab,'; done >$@ - -benchmarks/octave.csv: perf.m - for t in 1 2 3 4 5; do octave -q --eval perf 2>/dev/null; done >$@ - -benchmarks/r.csv: perf.R - for t in 1 2 3 4 5; do cat $< | R --vanilla --slave 2>/dev/null; done >$@ - -benchmarks/javascript.csv: perf.js - for t in 1 2 3 4 5; do node $<; done >$@ - -benchmarks/mathematica.csv: perf.nb - for t in 1 2 3 4 5; do $(MATHEMATICABIN) -noprompt -run "<<$<; Exit[]"; done >$@ - -BENCHMARKS = \ - benchmarks/c.csv \ - benchmarks/fortran.csv \ - benchmarks/go.csv \ - benchmarks/julia.csv \ - benchmarks/python.csv \ - benchmarks/matlab.csv \ - benchmarks/octave.csv \ - benchmarks/r.csv \ - benchmarks/javascript.csv \ - benchmarks/mathematica.csv - -benchmarks.csv: bin/collect.pl $(BENCHMARKS) - $(QUIET_PERL) $^ >$@ - -benchmarks.html: bin/table.pl benchmarks.csv - $(QUIET_PERL) $^ >$@ +micro kernel cat shootout: + @$(call spawn,$(JULIA_EXECUTABLE)) $@/perf.jl | perl -nle '@_=split/,/; printf "%-18s %8.3f\n", $$_[1], $$_[2]' clean: - @rm -rf perf.h bin/perf* bin/fperf* benchmarks/*.csv benchmarks.csv *.mod + rm -f *~ + $(MAKE) -C micro $@ -.PHONY: all perf clean +.PHONY: micro kernel cat shootout clean diff --git a/test/perf_cat.jl b/test/perf/cat/perf.jl similarity index 66% rename from test/perf_cat.jl rename to test/perf/cat/perf.jl index ddfecd5df1f83..b4a2c8a1b197e 100644 --- a/test/perf_cat.jl +++ b/test/perf/cat/perf.jl @@ -1,3 +1,5 @@ +include("../perfutil.jl") + function cat2d_perf(n, iter) a = rand(n,n) b = rand(n,n) @@ -10,7 +12,7 @@ function cat2d_perf2(n, iter) a = rand(n,n) b = rand(n,n) for i=1:iter - c = Array(Float64, 2n, 2n) + c = Array(Float64,2n,2n) c[1:n,1:n] = a c[1:n,n+1:end] = b c[n+1:end,1:n] = b @@ -19,11 +21,11 @@ function cat2d_perf2(n, iter) end end -@timeit cat2d_perf(5, 20000) "small cat" -@timeit cat2d_perf2(5, 20000) "small cat 2" +@timeit cat2d_perf(5,20000) "small_cat" +@timeit cat2d_perf2(5,20000) "small_cat_2" -@timeit cat2d_perf(500, 2) "large cat" -@timeit cat2d_perf2(500, 2) "large cat 2" +@timeit cat2d_perf(500,2) "large_cat" +@timeit cat2d_perf2(500,2) "large_cat_2" function hcat_perf(n, iter) a = rand(n,n) @@ -45,11 +47,11 @@ function hcat_perf2(n, iter) end end -@timeit hcat_perf(5, 20000) "small hcat" -@timeit hcat_perf2(5, 20000) "small hcat 2" +@timeit hcat_perf(5,20000) "small_hcat" +@timeit hcat_perf2(5,20000) "small_hcat_2" -@timeit hcat_perf(500, 2) "large hcat" -@timeit hcat_perf2(500, 2) "large hcat 2" +@timeit hcat_perf(500,2) "large_hcat" +@timeit hcat_perf2(500,2) "large_hcat_2" function vcat_perf(n, iter) a = rand(n,n) @@ -71,11 +73,11 @@ function vcat_perf2(n, iter) end end -@timeit vcat_perf(5, 20000) "small vcat" -@timeit vcat_perf2(5, 20000) "small vcat 2" +@timeit vcat_perf(5,20000) "small_vcat" +@timeit vcat_perf2(5,20000) "small_vcat_2" -@timeit vcat_perf(500, 2) "large vcat" -@timeit vcat_perf2(500, 2) "large vcat 2" +@timeit vcat_perf(500,2) "large_vcat" +@timeit vcat_perf2(500,2) "large_vcat_2" function catnd_perf(n, iter) a = rand(1,n,n,1) @@ -97,8 +99,8 @@ function catnd_perf2(n, iter) end end -@timeit catnd_perf(5, 20000) "small catnd" -@timeit catnd_perf2(5, 20000) "small catnd 2" +@timeit catnd_perf(5,20000) "small_catnd" +@timeit catnd_perf2(5,20000) "small_catnd_2" -@timeit catnd_perf(500, 2) "large catnd" -@timeit catnd_perf2(500, 2) "large catnd 2" +@timeit catnd_perf(500,2) "large_catnd" +@timeit catnd_perf2(500,2) "large_catnd_2" diff --git a/test/perf/functions.do b/test/perf/functions.do deleted file mode 100644 index 530d717fcbe02..0000000000000 --- a/test/perf/functions.do +++ /dev/null @@ -1,173 +0,0 @@ -clear mata -mata: - -// Timer function -void timeit(name, pointer(real scalar function) scalar func,arg) { - lang = "Mata (Stata)" - nexpt = 5 - times = J(nexpt, 1, 0) - - timer_clear() - for (i=1;i<=nexpt;i++) { - timer_on(i) - a = (*func)(arg) - timer_off(i) - t = timer_value(i) - times[i] = t[1] - } - - times = sort(times,1) - printf ("%s,%s,%4.0f\n", lang, name, 1000*times[1]) -} -mata mosave timeit(), replace - -// Recursive Fibonacci -real scalar fib(n) { - if (n < 2) { - return(n) - } else { - return(fib(n-1) + fib(n-2)) - } -} -mata mosave fib(), replace - -// Mandelbrot -scalar mandel(z) { - n = 0 - c = z - while (abs(z)<=2 & n<=79) { - z = z^2+c - n++ - } - return(n) -} -mata mosave mandel(), replace - -matrix mandelperf(ignore) { - a = range(-2,.5,.1) - b = range(-1,1,.1) - M = J(rows(a),rows(b),0) - count = 1 - for (r=1;r<=rows(a);r++) { - for (i=1;i<=rows(b);i++) { - M[r,i] = mandel(a[r] + b[i]*1i); - count = count + 1; - } - } - return(M) -} -mata mosave mandelperf(), replace - -// Numeric vector quicksort - -matrix qsort(a) { - return(qsort_kernel(a, 1, length(a))) -} -mata mosave qsort(), replace - -matrix qsort_kernel(a, lo, hi) { - i = lo - j = hi - while (i < hi) { - pivot = a[floor((lo+hi)/2)] - while (i <= j) { - while (a[i] < pivot) i++ - while (a[j] > pivot) j-- - if (i <= j) { - t = a[i] - a[i] = a[j] - a[j] = t - i = i + 1 - j = j - 1 - } - } - if (lo < j) a=qsort_kernel(a, lo, j) - lo = i - j = hi - } - return(a) -} -mata mosave qsort_kernel(), replace - -matrix sortperf(n) { - v = runiform(n,1) - v = qsort(v) -} -mata mosave sortperf(), replace - -// Slow pi series -scalar pisum(ignore) { - sum = 0 - for (j=1;j<=500;j++) { - sum = 0 - for (k=1;k<=10000;k++) { - sum = sum + 1/(k*k); - } - } - return(sum) -} -mata mosave pisum(), replace - -// Slow pi series, vectorized -scalar pisumvec(ignore) { - a = range(1,10000,1) - for (j=1;j<=500;j++) { - s = sum(1:/(a:^2)) - } - return(s) -} -mata mosave pisumvec(), replace - -// Random matrix statistics -matrix randmatstat(t) { - n=5; - v = w = J(t,1,0) - for (i=1;i<=t;i++) { - a = runiform(n, n) - b = runiform(n, n) - c = runiform(n, n) - d = runiform(n, n) - P = a,b,c,d - Q = (a,b)\(c,d) - PP = P'P - QQ = Q'Q - v[i] = trace(PP*PP*PP*PP) - w[i] = trace(QQ*QQ*QQ*QQ) - } - return((sqrt(variance(v))/mean(v),sqrt(variance(w))/mean(w))) -} -mata mosave randmatstat(), replace - -// Largish random number gen & matmul -matrix randmatmul(n) { - return(runiform(n,n)*runiform(n,n)) -} -mata mosave randmatmul(), replace - -// printf -// On windows /dev/null should become NUL but doesn't work -void printfd(n) { - filename = "test.txt" - u = _unlink(filename) - f = fopen(filename, "w") - for (i=1;i<=n;i++) { - fput(f,sprintf("%d %d\n", i, i)) - } - fclose(f) -} -mata mosave printfd(), replace - -end - -exit - - -// Parse Int -real scalar parseintperf(t) { - for (i=1;i<=t;i++) { - n = int(runiform(1,1)*(2^32)) - s = dec2hex(n); - m = hex2dec(s); - } - return(n) -} diff --git a/test/perf2/actor_centrality.jl b/test/perf/kernel/actor_centrality.jl similarity index 94% rename from test/perf2/actor_centrality.jl rename to test/perf/kernel/actor_centrality.jl index a37cd7423dff3..829cca869c2bd 100644 --- a/test/perf2/actor_centrality.jl +++ b/test/perf/kernel/actor_centrality.jl @@ -39,7 +39,7 @@ function read_graph() G = Graph() actors = Set() - open("imdb-1.tsv", "r") do io + open(joinpath(JULIA_HOME,"..","..","test","perf","kernel","imdb-1.tsv"), "r") do io while !eof(io) k = split(strip(readline(io)), "\t") actor, movie = k[1], join(k[2:3], "_") diff --git a/test/perf2/bench_eu.jl b/test/perf/kernel/bench_eu.jl similarity index 100% rename from test/perf2/bench_eu.jl rename to test/perf/kernel/bench_eu.jl diff --git a/test/perf2/bench_eu.m b/test/perf/kernel/bench_eu.m similarity index 100% rename from test/perf2/bench_eu.m rename to test/perf/kernel/bench_eu.m diff --git a/test/perf2/gk.jl b/test/perf/kernel/gk.jl similarity index 100% rename from test/perf2/gk.jl rename to test/perf/kernel/gk.jl diff --git a/test/perf2/gk.m b/test/perf/kernel/gk.m similarity index 100% rename from test/perf2/gk.m rename to test/perf/kernel/gk.m diff --git a/test/perf2/go_benchmark.c b/test/perf/kernel/go_benchmark.c similarity index 100% rename from test/perf2/go_benchmark.c rename to test/perf/kernel/go_benchmark.c diff --git a/test/perf2/go_benchmark.jl b/test/perf/kernel/go_benchmark.jl similarity index 100% rename from test/perf2/go_benchmark.jl rename to test/perf/kernel/go_benchmark.jl diff --git a/test/perf2/imdb-1.tsv b/test/perf/kernel/imdb-1.tsv similarity index 100% rename from test/perf2/imdb-1.tsv rename to test/perf/kernel/imdb-1.tsv diff --git a/test/perf2/json.jl b/test/perf/kernel/json.jl similarity index 100% rename from test/perf2/json.jl rename to test/perf/kernel/json.jl diff --git a/test/perf2/laplace.jl b/test/perf/kernel/laplace.jl similarity index 100% rename from test/perf2/laplace.jl rename to test/perf/kernel/laplace.jl diff --git a/test/perf2/laplace/c_laplace.c b/test/perf/kernel/laplace/c_laplace.c similarity index 100% rename from test/perf2/laplace/c_laplace.c rename to test/perf/kernel/laplace/c_laplace.c diff --git a/test/perf2/laplace/c_laplace_parallel_update.c b/test/perf/kernel/laplace/c_laplace_parallel_update.c similarity index 100% rename from test/perf2/laplace/c_laplace_parallel_update.c rename to test/perf/kernel/laplace/c_laplace_parallel_update.c diff --git a/test/perf2/laplace/c_laplace_parallel_update_pointer.c b/test/perf/kernel/laplace/c_laplace_parallel_update_pointer.c similarity index 100% rename from test/perf2/laplace/c_laplace_parallel_update_pointer.c rename to test/perf/kernel/laplace/c_laplace_parallel_update_pointer.c diff --git a/test/perf2/laplace/cilk_laplace.c b/test/perf/kernel/laplace/cilk_laplace.c similarity index 100% rename from test/perf2/laplace/cilk_laplace.c rename to test/perf/kernel/laplace/cilk_laplace.c diff --git a/test/perf2/laplace/for_laplace.f90 b/test/perf/kernel/laplace/for_laplace.f90 similarity index 100% rename from test/perf2/laplace/for_laplace.f90 rename to test/perf/kernel/laplace/for_laplace.f90 diff --git a/test/perf2/laplace/laplace.m b/test/perf/kernel/laplace/laplace.m similarity index 100% rename from test/perf2/laplace/laplace.m rename to test/perf/kernel/laplace/laplace.m diff --git a/test/perf2/laplace/laplace2.py b/test/perf/kernel/laplace/laplace2.py similarity index 100% rename from test/perf2/laplace/laplace2.py rename to test/perf/kernel/laplace/laplace2.py diff --git a/test/perf2/laplace/laplace_for_update1.f90 b/test/perf/kernel/laplace/laplace_for_update1.f90 similarity index 100% rename from test/perf2/laplace/laplace_for_update1.f90 rename to test/perf/kernel/laplace/laplace_for_update1.f90 diff --git a/test/perf2/laplace/laplace_for_update2.f90 b/test/perf/kernel/laplace/laplace_for_update2.f90 similarity index 100% rename from test/perf2/laplace/laplace_for_update2.f90 rename to test/perf/kernel/laplace/laplace_for_update2.f90 diff --git a/test/perf2/perf2.jl b/test/perf/kernel/perf.jl similarity index 93% rename from test/perf2/perf2.jl rename to test/perf/kernel/perf.jl index eaf81abaf66d4..de32bfa8d6f54 100644 --- a/test/perf2/perf2.jl +++ b/test/perf/kernel/perf.jl @@ -1,20 +1,4 @@ -macro timeit(ex,name) - quote - t = Inf - for i=1:5 - t = min(t, @elapsed $ex) - end - println($name, "\t", t*1000) - end -end - -macro timeit1(ex,name) - quote - println($name, "\t", (@elapsed $ex)*1000) - end -end - -srand(1776) # get more consistent times +include("../perfutil.jl") require("$JULIA_HOME/../../examples/list.jl") @@ -26,7 +10,7 @@ function listn1n2(n1::Int,n2::Int) l1 end -@timeit listn1n2(1,10^6) "cons " +@timeit listn1n2(1,10^6) "cons" gc() # issue #1211 @@ -36,7 +20,7 @@ a = Array(Float64, 1000000) # issue #950 include("gk.jl") -@timeit gk(350,[0.1]) "gk " +@timeit gk(350,[0.1]) "gk" # issue #942 s = sparse(ones(280,280)); @@ -73,7 +57,7 @@ include("go_benchmark.jl") # issue #3142 include("simplex.jl") -simplexbenchmark() +@timeit doTwoPassRatioTest() "simplex" function cmp_with_func(x::Vector, f::Function) count::Int = 0 @@ -86,7 +70,7 @@ function cmp_with_func(x::Vector, f::Function) end x = randn(200_000) -@timeit (for n in 1:10; count = cmp_with_func(x, isless) end) "funarg " +@timeit (for n in 1:10; count = cmp_with_func(x, isless) end) "funarg" function arith_vectorized(b,c,d) @@ -98,7 +82,7 @@ b = randn(len) c = randn(len) d = randn(len) -@timeit (for n in 1:10; a = arith_vectorized(b,c,d); end) "vectoriz" +@timeit (for n in 1:10; a = arith_vectorized(b,c,d); end) "vectorize" open("random.csv","w") do io writecsv(io, rand(100000,4)) diff --git a/test/perf2/simplex.jl b/test/perf/kernel/simplex.jl similarity index 94% rename from test/perf2/simplex.jl rename to test/perf/kernel/simplex.jl index 1fd5f085ff28e..f5a965e02b648 100644 --- a/test/perf2/simplex.jl +++ b/test/perf/kernel/simplex.jl @@ -68,13 +68,3 @@ function doTwoPassRatioTest() return time() - t end - -function simplexbenchmark() - - t = Inf - for k in 1:5 - t = min(t,doTwoPassRatioTest()) - end - println("simplex\t\t",1000*t) - -end diff --git a/test/perf2/stockcorr.jl b/test/perf/kernel/stockcorr.jl similarity index 100% rename from test/perf2/stockcorr.jl rename to test/perf/kernel/stockcorr.jl diff --git a/test/perf2/stockcorr.m b/test/perf/kernel/stockcorr.m similarity index 100% rename from test/perf2/stockcorr.m rename to test/perf/kernel/stockcorr.m diff --git a/test/perf2/ziggurat.c b/test/perf/kernel/ziggurat.c similarity index 100% rename from test/perf2/ziggurat.c rename to test/perf/kernel/ziggurat.c diff --git a/test/perf2/ziggurat.jl b/test/perf/kernel/ziggurat.jl similarity index 100% rename from test/perf2/ziggurat.jl rename to test/perf/kernel/ziggurat.jl diff --git a/test/perf/micro/Makefile b/test/perf/micro/Makefile new file mode 100644 index 0000000000000..2cf1a826f1a77 --- /dev/null +++ b/test/perf/micro/Makefile @@ -0,0 +1,94 @@ +JULIAHOME = $(abspath ../../..) +include $(JULIAHOME)/Make.inc +include $(JULIAHOME)/deps/Versions.make + +ifeq ($(OS), WINNT) +MATHEMATICABIN = MathKernel +else ifeq ($(OS), Darwin) +MATHEMATICABIN = MathKernel +else +MATHEMATICABIN = math +endif + +default: benchmarks.html + +export OMP_NUM_THREADS=1 +export GOTO_NUM_THREADS=1 +export OPENBLAS_NUM_THREADS=1 + +perf.h: $(JULIAHOME)/deps/Versions.make + echo '#include "$(JULIAHOME)/deps/openblas-$(OPENBLAS_VER)/cblas.h"' > $@ + echo '#include "$(JULIAHOME)/deps/random/dsfmt-$(DSFMT_VER)/dSFMT.c"' >> $@ + +bin/perf%: perf.c perf.h + $(CC) -std=c99 -O$* $< -o $@ $(JULIAHOME)/deps/openblas-$(OPENBLAS_VER)/libopenblas.a -lpthread + +bin/fperf%: perf.f90 + $(FC) -static-libgfortran -O$* -fexternal-blas $< -o $@ $(JULIAHOME)/deps/openblas-$(OPENBLAS_VER)/libopenblas.a -lpthread + +benchmarks/c.csv: \ + benchmarks/c0.csv \ + benchmarks/c1.csv \ + benchmarks/c2.csv \ + benchmarks/c3.csv + cat $^ > $@ + +benchmarks/fortran.csv: \ + benchmarks/fortran0.csv \ + benchmarks/fortran1.csv \ + benchmarks/fortran2.csv \ + benchmarks/fortran3.csv + cat $^ > $@ + +benchmarks/c%.csv: bin/perf% + for t in 1 2 3 4 5; do $<; done >$@ + +benchmarks/fortran%.csv: bin/fperf% + for t in 1 2 3 4 5; do $<; done >$@ + +benchmarks/go.csv: perf.go + for t in 1 2 3 4 5; do go run $<; done >$@ + +benchmarks/julia.csv: perf.jl + for t in 1 2 3 4 5; do ../../julia $<; done >$@ + +benchmarks/python.csv: perf.py + for t in 1 2 3 4 5; do python $<; done >$@ + +benchmarks/matlab.csv: perf.m + for t in 1 2 3 4 5; do matlab -nosplash -nodesktop -nojvm -r 'perf;exit' 2>/dev/null | grep '^matlab,'; done >$@ + +benchmarks/octave.csv: perf.m + for t in 1 2 3 4 5; do octave -q --eval perf 2>/dev/null; done >$@ + +benchmarks/r.csv: perf.R + for t in 1 2 3 4 5; do cat $< | R --vanilla --slave 2>/dev/null; done >$@ + +benchmarks/javascript.csv: perf.js + for t in 1 2 3 4 5; do node $<; done >$@ + +benchmarks/mathematica.csv: perf.nb + for t in 1 2 3 4 5; do $(MATHEMATICABIN) -noprompt -run "<<$<; Exit[]"; done >$@ + +BENCHMARKS = \ + benchmarks/c.csv \ + benchmarks/fortran.csv \ + benchmarks/go.csv \ + benchmarks/julia.csv \ + benchmarks/python.csv \ + benchmarks/matlab.csv \ + benchmarks/octave.csv \ + benchmarks/r.csv \ + benchmarks/javascript.csv \ + benchmarks/mathematica.csv + +benchmarks.csv: bin/collect.pl $(BENCHMARKS) + $(QUIET_PERL) $^ >$@ + +benchmarks.html: bin/table.pl benchmarks.csv + $(QUIET_PERL) $^ >$@ + +clean: + @rm -rf perf.h bin/perf* bin/fperf* benchmarks/*.csv benchmarks.csv *.mod *~ + +.PHONY: all perf clean diff --git a/test/perf/benchmarks/.gitignore b/test/perf/micro/benchmarks/.gitignore similarity index 100% rename from test/perf/benchmarks/.gitignore rename to test/perf/micro/benchmarks/.gitignore diff --git a/test/perf/bin/.gitignore b/test/perf/micro/bin/.gitignore similarity index 100% rename from test/perf/bin/.gitignore rename to test/perf/micro/bin/.gitignore diff --git a/test/perf/bin/collect.pl b/test/perf/micro/bin/collect.pl similarity index 100% rename from test/perf/bin/collect.pl rename to test/perf/micro/bin/collect.pl diff --git a/test/perf/bin/table.pl b/test/perf/micro/bin/table.pl similarity index 100% rename from test/perf/bin/table.pl rename to test/perf/micro/bin/table.pl diff --git a/test/perf/perf.R b/test/perf/micro/perf.R similarity index 100% rename from test/perf/perf.R rename to test/perf/micro/perf.R diff --git a/test/perf/perf.c b/test/perf/micro/perf.c similarity index 99% rename from test/perf/perf.c rename to test/perf/micro/perf.c index e06e59a04c155..315e9fb295afb 100644 --- a/test/perf/perf.c +++ b/test/perf/micro/perf.c @@ -2,7 +2,7 @@ #define DSFMT_MEXP 19937 #include "perf.h" -#include "../../deps/random/randmtzig.c" +#include "../../../deps/random/randmtzig.c" double *myrand(int n) { double *d = (double *)malloc(n*sizeof(double)); diff --git a/test/perf/perf.f90 b/test/perf/micro/perf.f90 similarity index 100% rename from test/perf/perf.f90 rename to test/perf/micro/perf.f90 diff --git a/test/perf/perf.go b/test/perf/micro/perf.go similarity index 100% rename from test/perf/perf.go rename to test/perf/micro/perf.go diff --git a/test/perf/perf.jl b/test/perf/micro/perf.jl similarity index 89% rename from test/perf/perf.jl rename to test/perf/micro/perf.jl index a7cc656313d78..809838e37a740 100644 --- a/test/perf/perf.jl +++ b/test/perf/micro/perf.jl @@ -1,19 +1,6 @@ using Base.Test -print_output = isempty(ARGS) || contains(ARGS, "perf/perf.jl") || contains(ARGS, "perf") - -macro timeit(ex,name) - quote - t = Inf - for i=1:5 - t = min(t, @elapsed $ex) - end - if print_output - println("julia,", $name, ",", t*1000) - end - #gc() - end -end +include("../perfutil.jl") ## recursive fib ## diff --git a/test/perf/perf.js b/test/perf/micro/perf.js similarity index 100% rename from test/perf/perf.js rename to test/perf/micro/perf.js diff --git a/test/perf/perf.lua b/test/perf/micro/perf.lua similarity index 100% rename from test/perf/perf.lua rename to test/perf/micro/perf.lua diff --git a/test/perf/perf.m b/test/perf/micro/perf.m similarity index 100% rename from test/perf/perf.m rename to test/perf/micro/perf.m diff --git a/test/perf/perf.nb b/test/perf/micro/perf.nb similarity index 100% rename from test/perf/perf.nb rename to test/perf/micro/perf.nb diff --git a/test/perf/perf.py b/test/perf/micro/perf.py similarity index 100% rename from test/perf/perf.py rename to test/perf/micro/perf.py diff --git a/test/perf/perf.do b/test/perf/perf.do deleted file mode 100644 index 0cef0ef285bea..0000000000000 --- a/test/perf/perf.do +++ /dev/null @@ -1,43 +0,0 @@ -clear -clear mata -run functions.do -mata: - - -// 1. Test if functions function -// I. Recursive Fibonacci. Fib(20)=6765 -printf("Fib(20) = %5.0f\n",fib(20)) -// II. Parse Int -// Seems to make no sense in Stata -// III. Mandelbrot set: complex arithmetic and comprehensions -// Should be 14628 according to original Matlab code. -mandel(-.53+.68i) -sum(sum(mandelperf(1))) -// IV. Quicksort -qsort(runiform(5,1)) -// V. Pi (Should give 1.644834071848065) -pisum(1) -pisumvec(1) -// VI. Random matrix statistics -// First one should be > .5 and second < 1 according to original Matlab code -randmatstat(100) -// Largish random number gen & matmul -randmatmul(100) -// I/O -// Can't find a way to output to /dev/null in Windows :) -// printfd(1) - -// 2. Time functions -{ -timeit("fib", &fib(), 20) -// timeit("parse_int", &parseintperf(), 1000) -timeit("mandel", &mandelperf(), 1) -timeit("quicksort", &sortperf(), 5000) -timeit("pi_sum",&pisum(), 1) -timeit("pi_sum_vec",&pisumvec(), 1) -timeit("rand_mat_stat", &randmatstat(), 1000) -timeit("rand_mat_mul", &randmatmul(), 1000) -// timeit("printfd", &printfd(), 100000) -} - -end diff --git a/test/perf/perfutil.jl b/test/perf/perfutil.jl new file mode 100644 index 0000000000000..8eb08dd44aa32 --- /dev/null +++ b/test/perf/perfutil.jl @@ -0,0 +1,23 @@ +print_output = isempty(ARGS) || contains(ARGS, "perf/perf.jl") || contains(ARGS, "perf") + +macro timeit(ex,name) + quote + t = Inf + for i=1:5 + t = min(t, @elapsed $ex) + gc() + end + if print_output + println("julia,", $name, ",", t*1000) + end + end +end + +macro timeit1(ex,name) + quote + @printf "julia,%s,%f\n" $name (@elapsed $ex)*1000 + gc() + end +end + +srand(1776) # get more consistent times diff --git a/examples/shootout/README b/test/perf/shootout/README similarity index 100% rename from examples/shootout/README rename to test/perf/shootout/README diff --git a/examples/shootout/binary-trees.jl b/test/perf/shootout/binary_trees.jl similarity index 75% rename from examples/shootout/binary-trees.jl rename to test/perf/shootout/binary_trees.jl index 21270b6176818..4cd722a5f6fb3 100644 --- a/examples/shootout/binary-trees.jl +++ b/test/perf/shootout/binary_trees.jl @@ -36,30 +36,24 @@ function loop_depths(d, min_depth, max_depth) for j = 1:niter c += check(make(i, d)) + check(make(-i, d)) end - @printf("%i\t trees of depth %i\t check: %i\n", 2*niter, d, c) +# @printf("%i\t trees of depth %i\t check: %i\n", 2*niter, d, c) d += 2 end end -function binary_trees(N::Int) +function binary_trees(N::Int=10) const min_depth = 4 const max_depth = N const stretch_depth = max_depth + 1 # create and check stretch tree let c = check(make(0, stretch_depth)) - @printf("stretch tree of depth %i\t check: %i\n", stretch_depth, c) +# @printf("stretch tree of depth %i\t check: %i\n", stretch_depth, c) end long_lived_tree = make(0, max_depth) loop_depths(min_depth, min_depth, max_depth) - @printf("long lived tree of depth %i\t check: %i\n", max_depth, check(long_lived_tree)) +# @printf("long lived tree of depth %i\t check: %i\n", max_depth, check(long_lived_tree)) end -if length(ARGS) >= 1 - N = int(ARGS[1]) -else - N = 10 -end -binary_trees(N) diff --git a/examples/shootout/fannkuch.jl b/test/perf/shootout/fannkuch.jl similarity index 90% rename from examples/shootout/fannkuch.jl rename to test/perf/shootout/fannkuch.jl index 2a884bc4553df..d53d7f1fe8d1c 100644 --- a/examples/shootout/fannkuch.jl +++ b/test/perf/shootout/fannkuch.jl @@ -71,9 +71,3 @@ function fannkuch(n) end end end -if length(ARGS) >= 1 - N = int(ARGS[1]) -else - N = 7 -end -@printf("Pfannkuchen(%i) = %i\n", N, fannkuch(N)) diff --git a/examples/shootout/fasta.jl b/test/perf/shootout/fasta.jl similarity index 75% rename from examples/shootout/fasta.jl rename to test/perf/shootout/fasta.jl index f8e4fe9d841f5..24e43fe1b0f40 100644 --- a/examples/shootout/fasta.jl +++ b/test/perf/shootout/fasta.jl @@ -39,14 +39,14 @@ function repeat_fasta(src, n) k = length(src) s = string(src, src, src[1:n % k]) - for j = 0:div(n, line_width) - 1 - i = j * line_width % k - println(s[i + 1:i + line_width]) - end - - if n % line_width > 0 - println(s[end - (n % line_width) + 1:]) - end +# for j = 0:div(n, line_width) - 1 +# i = j * line_width % k +# println(s[i + 1:i + line_width]) +# end + +# if n % line_width > 0 +# println(s[end - (n % line_width) + 1:]) +# end end @@ -77,21 +77,7 @@ function random_fasta(symb, pr, n) for i = 1:m line[i] = symb[choose_char(cs)] end - write(line[1:m]); println() +# write(line[1:m]); println() k -= line_width end end - - - -const n = int(ARGS[1]) - -println(">ONE Homo sapiens alu") -repeat_fasta(alu, 2n) - -println(">TWO IUB ambiguity codes") -random_fasta(iub[1], iub[2], 3n) - -println(">THREE Homo sapiens frequency") -random_fasta(homosapiens[1], homosapiens[2], 5n) - diff --git a/examples/shootout/k-nucleotide.jl b/test/perf/shootout/k_nucleotide.jl similarity index 98% rename from examples/shootout/k-nucleotide.jl rename to test/perf/shootout/k_nucleotide.jl index 06681ae2db926..8411918b8b6c9 100644 --- a/examples/shootout/k-nucleotide.jl +++ b/test/perf/shootout/k_nucleotide.jl @@ -56,7 +56,7 @@ function print_knucs(a::Array{KNuc, 1}) println() end -function main() +function k_nucleotide() three = ">THREE " while true line = readline(STDIN) @@ -85,5 +85,3 @@ function main() @printf("%d\t%s\n", count_one(str, s), s) end end - -main() diff --git a/examples/shootout/mandelbrot.jl b/test/perf/shootout/mandelbrot.jl similarity index 76% rename from examples/shootout/mandelbrot.jl rename to test/perf/shootout/mandelbrot.jl index 29959d709438c..59f36880afa25 100644 --- a/examples/shootout/mandelbrot.jl +++ b/test/perf/shootout/mandelbrot.jl @@ -5,7 +5,7 @@ const ITER = 50 -function mandel(z::Complex128) +function ismandel(z::Complex128) c = z for n = 1:ITER if abs2(z) > 4 @@ -21,20 +21,14 @@ function draw_mandel(M::Array{Uint8, 2}, n::Int) ci = 2y/n - 1 for x = 0:n-1 c = complex(2x/n - 1.5, ci) - if mandel(c) + if ismandel(c) M[div(x, 8) + 1, y + 1] |= 1 << uint8(7 - x%8) end end end end -function main(args, stream) - if length(args) > 0 - n = int(args[1]) - else - n = 200 - end - +function mandel(n=800, stream=STDOUT) if n%8 != 0 error("Error: n of $n is not divisible by 8") end @@ -45,6 +39,3 @@ function main(args, stream) write(stream, M) flush(stream) end - -#main([1600], open("mandel.txt", "w")) -main(ARGS, STDOUT) diff --git a/examples/shootout/meteor-contest.jl b/test/perf/shootout/meteor_contest.jl similarity index 95% rename from examples/shootout/meteor-contest.jl rename to test/perf/shootout/meteor_contest.jl index e34d040be6bd3..f1e61f0c5cdba 100644 --- a/examples/shootout/meteor-contest.jl +++ b/test/perf/shootout/meteor_contest.jl @@ -231,20 +231,12 @@ function printSolution(s) end end -function main() - if length(ARGS) < 1 - n = 2098 - else - n = int(ARGS[1]) - end - +function meteor_contest(n::Int=2098) solve(n) - println("$(length(solutions)) solutions found") - println() - printSolution(min(solutions)) - println() - printSolution(max(solutions)) - println() +# println("$(length(solutions)) solutions found") +# println() +# printSolution(min(solutions)) +# println() +# printSolution(max(solutions)) +# println() end - -main() diff --git a/examples/shootout/nbody.jl b/test/perf/shootout/nbody.jl similarity index 94% rename from examples/shootout/nbody.jl rename to test/perf/shootout/nbody.jl index d8ba9328fe6d8..848418961b534 100644 --- a/examples/shootout/nbody.jl +++ b/test/perf/shootout/nbody.jl @@ -6,7 +6,7 @@ # A straight port from the Java version # -include("timing.jl") +module NBody # Constants const solar_mass = 4 * pi * pi @@ -121,19 +121,13 @@ function energy(bodies) end -function nbody(N::Int) +function nbody(N::Int=1000) init_sun(bodies) - @printf("%.9f\n", energy(bodies)) +# @printf("%.9f\n", energy(bodies)) for i = 1:N advance(bodies, 0.01) end - @printf("%.9f\n", energy(bodies)) +# @printf("%.9f\n", energy(bodies)) end -# main -if length(ARGS) >= 1 - N = int(ARGS[1]) -else - N = 1000 -end -@timeit nbody(N) "nbody" +end # module diff --git a/examples/shootout/nbody_vec.jl b/test/perf/shootout/nbody_vec.jl similarity index 93% rename from examples/shootout/nbody_vec.jl rename to test/perf/shootout/nbody_vec.jl index 82ca4baa2325a..6109e5e7705f7 100644 --- a/examples/shootout/nbody_vec.jl +++ b/test/perf/shootout/nbody_vec.jl @@ -6,7 +6,7 @@ # A vectorized version of the Java port from nbody.jl # -include("timing.jl") +module NBodyVec # Constants const solar_mass = 4 * pi * pi @@ -100,19 +100,13 @@ function energy(bodies) end -function nbody(N::Int) +function nbody_vec(N::Int=1000) init_sun(bodies) - @printf("%.9f\n", energy(bodies)) +# @printf("%.9f\n", energy(bodies)) for i = 1:N advance(bodies, 0.01) end - @printf("%.9f\n", energy(bodies)) +# @printf("%.9f\n", energy(bodies)) end -# main -if length(ARGS) >= 1 - N = int(ARGS[1]) -else - N = 1000 -end -@timeit nbody(N) "nbody" +end # module diff --git a/test/perf/shootout/perf.jl b/test/perf/shootout/perf.jl new file mode 100644 index 0000000000000..1292014d37a64 --- /dev/null +++ b/test/perf/shootout/perf.jl @@ -0,0 +1,45 @@ +include("../perfutil.jl") + +include("binary_trees.jl") +@timeit1 binary_trees(10) "binary_trees" + +include("fannkuch.jl") +@timeit1 fannkuch(7) "fannkuch" + +include("fasta.jl") +n = 100 +@timeit1 begin + repeat_fasta(alu, 2n) + random_fasta(iub[1], iub[2], 3n) + random_fasta(homosapiens[1], homosapiens[2], 5n) +end "fasta" + +include("k_nucleotide.jl") +#@timeit1 k_nucleotide() "k_nucleotide" + +include("mandelbrot.jl") +#@timeit1 mandel(n=800, stream=open("/dev/null", "w")) + +include("meteor_contest.jl") +@timeit1 meteor_contest() "meteor_contest" + +include("nbody.jl") +using NBody +@timeit1 NBody.nbody() "nbody" + +include("nbody_vec.jl") +using NBodyVec +@timeit1 NBodyVec.nbody_vec() "nbody_vec" + +include("pidigits.jl") +#@assert pidigits(1000) == 9216420198 +#@timeit1 pidigits(1000) "pidigits" + +include("regex_dna.jl") +#@timeit1 regex_dna() "regex_dna" + +include("revcomp.jl") +#@timeit1 revcomp() "revcomp" + +include("spectralnorm.jl") +@timeit1 spectralnorm() "spectralnorm" diff --git a/examples/shootout/pidigits.jl b/test/perf/shootout/pidigits.jl similarity index 87% rename from examples/shootout/pidigits.jl rename to test/perf/shootout/pidigits.jl index 20dbe02ecf19b..550763fa7b50c 100644 --- a/examples/shootout/pidigits.jl +++ b/test/perf/shootout/pidigits.jl @@ -1,5 +1,3 @@ -include("timing.jl") - function pidigits(N::Int, printOut::Bool) """ See http://shootout.alioth.debian.org/u64q/performance.php?test=pidigits#about @@ -59,17 +57,6 @@ function pidigits(N::Int, printOut::Bool) end end -function pidigits(N::Int) +function pidigits(N::Int=1000) pidigits(N,false) end - - -@assert pidigits(1000) == 9216420198 - -if length(ARGS)==1 - N = int(ARGS[1]) -else - N = 1000 -end -@timeit pidigits(N) "pidigits" - diff --git a/examples/shootout/regex-dna.jl b/test/perf/shootout/regex_dna.jl similarity index 97% rename from examples/shootout/regex-dna.jl rename to test/perf/shootout/regex_dna.jl index 02290ca5c63ca..d16e6ee3691e1 100644 --- a/examples/shootout/regex-dna.jl +++ b/test/perf/shootout/regex_dna.jl @@ -30,7 +30,7 @@ const subs = [ (r"Y", "(c|t)") ] -function main() +function regex_dna() seq = readall(STDIN) l1 = length(seq) @@ -55,4 +55,3 @@ function main() println(length(seq)) end -main() diff --git a/examples/shootout/revcomp.jl b/test/perf/shootout/revcomp.jl similarity index 91% rename from examples/shootout/revcomp.jl rename to test/perf/shootout/revcomp.jl index 283b2ba78d0bb..7ddaeb3a6c695 100644 --- a/examples/shootout/revcomp.jl +++ b/test/perf/shootout/revcomp.jl @@ -6,7 +6,7 @@ # FIXME(davekong) Is there support in Julia for doing more efficient IO and # handling of byte arrays? -const revcomp = { +const revcompdata = { 'A'=> 'T', 'a'=> 'T', 'C'=> 'G', 'c'=> 'G', 'G'=> 'C', 'g'=> 'C', @@ -37,7 +37,7 @@ function print_buff(b) end end -function main() +function revcomp() buff = Uint8[] while true line = readline(STDIN).data @@ -50,9 +50,8 @@ function main() write(line) else l = length(line)-1 - append!(buff, [uint8(revcomp[line[i]]) for i=1:l]) + append!(buff, [uint8(revcompdata[line[i]]) for i=1:l]) end end end -main() diff --git a/examples/shootout/spectralnorm.jl b/test/perf/shootout/spectralnorm.jl similarity index 84% rename from examples/shootout/spectralnorm.jl rename to test/perf/shootout/spectralnorm.jl index 830c560fcdb2c..2cb6796a7c484 100644 --- a/examples/shootout/spectralnorm.jl +++ b/test/perf/shootout/spectralnorm.jl @@ -6,8 +6,6 @@ # Based on the Javascript program # -include("timing.jl") - A(i,j) = 1.0 / ((i+j)*(i+j+1.0)/2.0+i+1.0) function Au(u,w) @@ -44,16 +42,9 @@ function approximate(n) return sqrt(vBv/vv) end -function spectralnorm(N) - @printf("%.09f\n", approximate(N)) -end - -if length(ARGS) >= 1 - N = int(ARGS[1]) -else - N = 100 +function spectralnorm(N::Int=100) + approximate(N) end -spectralnorm(N) # @assert spectralnorm(100) == 1.274219991 # @timeit spectralnorm(500) "spectralnorm(n=500)" diff --git a/test/readdlm.jl b/test/readdlm.jl index 4fa1676b26f3d..9567c3cfb8951 100644 --- a/test/readdlm.jl +++ b/test/readdlm.jl @@ -1,4 +1,4 @@ -dlm_data = readdlm(joinpath("perf2", "imdb-1.tsv"), '\t') +dlm_data = readdlm(joinpath("perf/perf2", "imdb-1.tsv"), '\t') @test size(dlm_data) == (31383,3) @test dlm_data[12345,2] == "Gladiator" diff --git a/test/runtests.jl b/test/runtests.jl index 78ce79d82c88c..f42d2fe579ec7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,7 +3,7 @@ testnames = ["core", "keywordargs", "numbers", "strings", "unicode", "linalg", "blas", "fft", "dsp", "sparse", "bitarray", "random", "math", "functional", "bigint", "sorting", "statistics", "spawn", "parallel", "priorityqueue", - "arpack", "file", "perf", "suitesparse", "version", + "arpack", "file", "suitesparse", "version", "resolve", "pollfd", "mpfr", "broadcast", "complex", "socket", "floatapprox", "readdlm", "regex"]