Next: , Previous: , Up: Basic Usage   [Contents][Index]


1.4.3 Simple Tests

This section shows some basic code examples of MicroBenchmark usage.

This code generates a minimal (and not very useful) C benchmark:

#include <mbenchmark/all.h>
#include <unistd.h>

static void
test (void *unused)
{
  (void) unused;
  usleep (1000);
}

MICRO_BENCHMARK_REGISTER_SIMPLE_TEST (test);
MICRO_BENCHMARK_MAIN ();

This file can be found on the source code tree at doc/examples/basic.c. Lets go through its parts:

This code could be compiled with a C++ compiler too. Nonetheless, C++14 or later code might use the features available through the C++ binding. This would be the equivalent example in C++:

(use-modules (mbenchmark))

(define (test . args)
  (usleep 1000))

(register-test! "test" #:test test)
(main (command-line))

This file can be found on the source code tree at doc/examples/basic.cxx. These are the main differences with the C interface:

This would be its Guile equivalent:

(use-modules (mbenchmark))

(define (test . args)
  (usleep 1000))

(register-test! "test" #:test test)
(main (command-line))

This file can be found on the source code tree at doc/examples/basic.scm. Let’s see its parts:

The execution of these examples would print something like this:

basic --brief --log-level=warn
Suite: basic (1 test execution)
====================================
Test Name | Iterations | It.Time (μ)
====================================
     test |       4026 |      1.22ms
====================================

Next: Directed Test Cases, Previous: Other Build Systems, Up: Basic Usage   [Contents][Index]