You are looking at historical revision 39367 of this page. It may differ significantly from its current revision.
micro-benchmark
This egg provides means to benchmark your code in a simple manner. It features traditional benchmarking with microsecond resolution as well as a different approach that has been inspired by: https://github.com/evanphx/benchmark-ips
Documentation
Usage
(import micro-benchmark)
Types
statistics-alist
runtimes
[type] statistics-alist : (or null (list-of (pair symbol *)))[type] runtimes : (list-of real)
Note runtimes are in microseconds (μs).
current-benchmark-iterations
[parameter] current-benchmark-iterationsThe default number of iterations. Initially 100.
current-benchmark-statistics-set
[parameter] current-benchmark-statistics-setThe set of generated statistics, 'verbose or 'normal.
benchmark-measure
[syntax] (benchmark-measure EXPR ...) -> realRuns the EXPR ... once & returns the runtime in microseconds.
benchmark-run
[syntax] (benchmark-run [ITERATIONS] EXPR) -> statistics-alist[syntax] (benchmark-run (ITERATIONS [STAT-ID]) EXPR ...) -> statistics-alist
Runs the EXPR ... ITERATIONS times and returns a micro-stats (generate-statistics) report.
: ITERATIONS ; fixnum ; defaults to (curren-benchmark-iterations) : STAT-ID ; symbol ; defaults to (current-benchmark-statistics-set)
benchmark-ips
[syntax] (benchmark-ips [SECONDS] EXPR) -> statistics-alist[syntax] (benchmark-ips ([SECONDS [WARMUPS [STAT-ID]]]) EXPR ...) -> statistics-alist
Determines how many times one can run the given EXPR ... per second and returns a (generate-statistics) report.
: SECONDS ; fixnum ; seconds of run while counting, defaults to 5 : WARMUPS ; fixnum ; seconds of run before counting, defaults to 2 : STAT-ID ; symbol ; statistics set generated
benchmark-measure-run
[syntax] (benchmark-measure-run ([ITERATIONS]) EXPR ...) -> runtimesReturns the ITERATIONS X (EXPR ...) runtimes.
: ITERATIONS ; fixnum ; defaults to (curren-benchmark-iterations)
benchmark-measure-ips
[syntax] (benchmark-measure-ips (begin EXPR ...)) -> runtimes[syntax] (benchmark-measure-ips ([SECONDS [WARMUPS]]) EXPR ...) -> runtimes
Determines how many times one can run the given EXPR ... per second and returns a list of the runtimes.
: SECONDS ; fixnum ; seconds of run while counting, defaults to 5 : WARMUPS ; fixnum ; seconds of run before counting, defaults to 2
run-benchmark-measure
[procedure] (run-benchmark-measure THUNK) -> realReturns the (THUNK) runtime in microseconds.
run-benchmark-ips
[procedure] (run-benchmark-ips THUNK [SECONDS [WARMUPS]]) -> runtimesDetermines how many times one can run the given (THUNK) per second and returns the runtimes.
: SECONDS ; fixnum ; seconds of run while counting, defaults to 5 : WARMUPS ; fixnum ; seconds of run before counting, defaults to 2
bigO
[procedure] (bigO VALUE) -> realReturns the Big O order for the (: VALUE real).
bigO=
bigO<
[procedure] (bigO= A B) -> boolean[procedure] (bigO< A B) -> boolean
Is the Big O order of (: A real) = | < (: B real).
bigO-compare
[procedure] (bigO-compare A B) -> fixnumReturns the Big O comparison order for the (: A real) < = > (: B real); -1, 0, 1.
Examples
(import micro-benchmark) ;; simply measure the runtime of the given fragment (benchmark-measure (sleep 2)) ;=> 2003822.22601318 ;; run code 3 times and return results (parameterize ((current-benchmark-iterations 3)) (benchmark-run () (sleep 1)) ) ;=> ((min . 1001227.66900635) (max . 1003503.40200806) (mean . 1002539.4710083) (standard-deviation . 1177.07300087724) ...) ;; find out how many iterations we can make per second (benchmark-ips () (sleep 2)) ;=> ((mean . 0.499209372899189) (standard-deviation . 0.000467949282862626) ...)
Requirements
Authors
Version history
: 0.0.1 ; C5 release.
License
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. A full copy of the GPL license can be found at <http://www.gnu.org/licenses/>.