7.8

top ← prev up next →

Atomichron

Atomichron is a microbenchmarking library. A microbenchmark is an experiment that measures the performance of a very small and isolated piece of code. Microbenchmarks are best used to test the performance of library code, not real world code — the performance of real world code is determined by complex environmental factors and variables that a microbenchmark cannot reproduce. Library code has to perform well in many different environments so these environmental factors can usually be ignored.

As a general rule of thumb, never write a microbenchmark to measure code that performs IO. This includes code that reads or writes files and code that talks to other computers over the network. The performance of such operations cannot be reliably reproduced or measured by Atomichron.

A predicate for microbenchmarks

name . Running the microbenchmark will construct num-iterations different builder function. Then each microexpression is run num-microexpression-iterations times and the total time for that microexpression is recorded. Microexpressions are run multiple times because for many microexpressions, a single run would take so little time that it would be difficult to accurately measure. Constructs a microbenchmark named. Running the microbenchmark will constructdifferent microexpressions using thefunction. Then each microexpression is runtimes and the total time for that microexpression is recorded. Microexpressions are run multiple times because for many microexpressions, a single run would take so little time that it would be difficult to accurately measure.

Examples:

> ( define num-iterations 100 ) > ( define size 1000 ) > ( define vec ( build-vector size values ) ) > ( define indices ( build-vector num-iterations ( λ ( _ ) ( random size ) ) ) ) > ( define vector-ref-benchmark ( make-microbenchmark #:name ' vector-ref-benchmark #:iterations num-iterations #:microexpression-iterations 1000 #:microexpression-builder ( λ ( iteration ) ( define i ( vector-ref indices iteration ) ) ( make-microexpression #:thunk ( λ ( ) ( vector-ref vec i ) ) ) ) ) ) > ( microbenchmark-run! vector-ref-benchmark ) (microbenchmark-result #:average-cpu-nanoseconds 20 #:average-gc-cpu-nanoseconds 0 #:average-real-nanoseconds 20 #:benchmark-name 'vector-ref-benchmark)

Runs benchmark and returns timing results.

microbenchmark-run! A predicate for microbenchmark results returned from

microbenchmark-run! time-apply Constructs a microbenchmark result. This function is normally not called by users. Instead results are retrieved from. Seefor an explanation of the differences between CPU time, real time, and GC CPU time.

result is for. Returns the name of the microbenchmark thatis for.

Returns the average number of nanoseconds of CPU processing time spent in evaluating a microexpression once.

Returns the average number of nanoseconds of real time that elapsed while evaluating a microexpression once.

microbenchmark-result-average-cpu-nanoseconds Returns the averages number of nanoseconds of CPU processing time spent on garbage collection while evaluating a microexpression once. This time is included in

A predicate for microexpressions

microexpression , which is a small and simple expression that is timed and executed repeatedly during a thunk . See make-microbenchmark Constructs a , which is a small and simple expression that is timed and executed repeatedly during a microbenchmark . Running the constructed microexpression calls. Seefor an example of how microbenchmarks construct microexpressions.