@@ -74,7 +74,7 @@ function print_results( iterations, elapsed )
7474end
7575
7676"""
77- benchmark( expr )
77+ benchmark( setup, expr )
7878
7979Run a benchmark.
8080
@@ -86,16 +86,17 @@ Run a benchmark.
8686
8787# Arguments
8888
89+ * `setup`: setup expression
8990* `expr`: expression to benchmark
9091
9192# Examples
9293
9394``` julia
94- julia> out = benchmark( :( sin( 3.14 ) ) );
95+ julia> out = benchmark( :(), :( sin( 3.14 ) ) );
9596```
9697"""
97- function benchmark ( expr )
98- t = eval ( :( BenchmarkTools. @benchmark $ expr samples= $ samples ) )
98+ function benchmark ( setup, expr )
99+ t = eval ( :( BenchmarkTools. @benchmark $ expr samples= $ samples setup = ( $ setup) ) )
99100
100101 # Compute the total "elapsed" time and convert from nanoseconds to seconds:
101102 s = sum ( t. times ) / 1.0e9 ;
@@ -108,26 +109,27 @@ function benchmark( expr )
108109end
109110
110111"""
111- bench( name, expr )
112+ bench( name, setup, expr )
112113
113114Run a named benchmark.
114115
115116# Arguments
116117
117118* `name`: benchmark name (suffix)
119+ * `setup`: setup expression
118120* `expr`: expression to benchmark
119121
120122# Examples
121123
122124``` julia
123- julia> bench( "sin", :( sin( 3.14 ) ) );
125+ julia> bench( "sin", :(), :( sin( 3.14 ) ) );
124126```
125127"""
126- function bench ( name, expr )
128+ function bench ( name, setup, expr )
127129 for i in 1 : repeats
128130 @printf ( " # julia::%s\n " , name );
129131 global count += 1 ;
130- results = benchmark ( expr );
132+ results = benchmark ( setup, expr );
131133 print_results ( results[ 1 ], results[ 2 ] );
132134 @printf ( " ok %d benchmark finished\n " , count );
133135 end
@@ -148,7 +150,7 @@ function main()
148150 print_version ();
149151
150152 # Run benchmark:
151- bench ( " TODO" , :( TODO ) );
153+ bench ( " TODO" , :(), :( TODO ) );
152154
153155 print_summary ( count, count );
154156end
0 commit comments