Menu

Tree [910eab] default tip /
 History

Read Only access


File Date Author Commit
 inst 2021-03-17 ederag ederag [910eab] fix bench_timeit
 COPYING 2011-06-24 carandraug carandraug [c935b4] Updated FSF address
 DESCRIPTION 2018-03-18 ederag ederag [cbc728] change name to benchmark2
 INDEX 2008-08-24 hauberg hauberg [f28863] Bumped version number
 README.md 2021-03-17 ederag ederag [6d2542] provide example
 screenshot.png 2018-05-05 ederag ederag [859d30] add screenshot

Read Me

benchmark2

This package contains codes used to measure Octave's speed.

It is an overhaul of the previous benchmark package.
The goal was to be able to adaptively change
the number of repetitions, until the duration is long enough,
like %timeit in ipython.

The simplest function is an equivalent for octave:

> bench_timeit("a = 2; a *= 3;")
     mean  3*sigma    units  benchmark
     0.44     0.02     (us)  "a = 2; a *= 3;"

More elaborate benchmarks can be put in script files with
a specific format, as shown in bench_example.m shipped with the package and listed below.
(%? is used instead of %! to avoid clash with test)

# optional, this preamble will be shared by all benchmarks
# found in this file:
%?common_preamble

a = 1:10;

# Beginning of a benchmark block:
%?benchmark name1
%?repeat 10

# code to be measured
a += 1;

# End of previous block, beginning of a benchmark block:
%?benchmark name2

b = 10 * 3;

# ...

# optional, but benchmark tools will stop here
%?endbenchmark

Yes, that's all!

The benchmark can then be run and results displayed:

> # benchmark_file = <your benchmark file path>
> benchmark_file = file_in_loadpath("bench_example.m");
> benchmarks = bench_parse(benchmark_file);
> updated_benchmarks = bench_run(benchmarks);
running "name1"...
running "name2"...
> bench_analyze(updated_benchmarks);

     mean  3*sigma    units  benchmark
     0.59     0.01     (us)  name1
     0.50     0.11     (us)  name2

> # after some changes, run benchmarks again
> updated_benchmarks_2 = bench_run(benchmarks);
running "name1"...
running "name2"...
> # compare multiple benchmarks (one column per run)
> bench_compare(updated_benchmarks, updated_benchmarks_2);
 5.86e-07 +- 1.2e-08  6.09e-07 +- 9.3e-09  name1
 4.95e-07 +- 1.1e-07  5.23e-07 +- 6.1e-09  name2

If cprintf is available, significantly better or worse timings are displayed in green or red.

For more info,

help bench_parse
help bench_run

Notes:

  • benchutil_* files are deprecated.

  • benchmark_* files were updated to the new framework.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.