
I learned I am trying to build a macro-benchmark, trying to measure realistic workloads or real-life situations, whereas a micro-benchmark aims to test an individual piece like a critical operation. The current build of the benchmark harness doesn’t have any options for parameterizing benchmarks, and I haven’t found a way to limit the number of iterations. Even for a small test, this takes a few seconds and I’d like to run less than 301 iterations, at the cost of statistical accuracy. I wanted to measure the performance of what I’d actually be running, rendering a test scene. The benchmark harness also runs at least 301 iterations, since N will be 1 if a single iteration takes longer than 1ms. Also libtest/stat.rs has a clean interface for summary statistics on an array of samples.I think this is to help with timing resolution problems? The shorter the benchmark the more it runs at once. Several runs are measured together, then averaged.There are some pretty neat things in here: check if converged after 100ms, and exit prematurely.run 50 iterations, measuring 5*N at a time.run 50 iterations, measuring N at a time.Determines how many runs per millisecond we can do, with a minimum of 1.Runs single iteration to get a rough time estimate.The iter function is the core of the test, it:
#RUST TEST BENCH CODE#
You code calls er with the inner closure. Then to setup the test, the bencher calls the outer function which has your setup code. When the bencher is run, it somehow collects functions with the # attribute and calls test::bench::benchmark. Looking at the source for libtest/lib.rs we can see how the benchmark gets run. People recommend putting your benchmarks under benches/ so nightly picks up the benchmarks, but stable doesn’t (which errors on using #!). Here we also had to use black_box which is an “opaque “black_box” to the optimizer”, so the compiler can’t optimize away our computation in the benchmark.Ĭurrently this is an “unstable” feature because the design hasn’t been finalized, so you’ll need to use nightly Rust. 0 passed 0 failed 0 ignored 1 measured 0 filtered out
