Benchmark
[Tools]
These functions allow you to add benchmark framework in a project for timing critical part and detect slow parts of code. More...
Defines | |
#define | EINA_BENCHMARK(function) ((Eina_Benchmark_Specimens)function) |
cast to an Eina_Benchmark_Specimens. | |
Typedefs | |
typedef struct _Eina_Benchmark | Eina_Benchmark |
Type for a benchmark. | |
typedef void(* | Eina_Benchmark_Specimens )(int request) |
Type for a test function to be called when running a benchmark. | |
Functions | |
Eina_Benchmark * | eina_benchmark_new (const char *name, const char *run) |
Create a new array. | |
void | eina_benchmark_free (Eina_Benchmark *bench) |
Free a benchmark object. | |
Eina_Bool | eina_benchmark_register (Eina_Benchmark *bench, const char *name, Eina_Benchmark_Specimens bench_cb, int count_start, int count_end, int count_step) |
Add a test to a benchmark. | |
Eina_Array * | eina_benchmark_run (Eina_Benchmark *bench) |
Run the benchmark tests that have been registered. |
Detailed Description
These functions allow you to add benchmark framework in a project for timing critical part and detect slow parts of code.
It is used in Eina to compare the time used by eina, glib, evas and ecore data types.
To use the benchmark module, Eina must be initialized with eina_init() and later shut down with eina_shutdown(). A benchmark is created with eina_benchmark_new() and freed with eina_benchmark_free().
eina_benchmark_register() adds a test to a benchmark. That test can be run a certain amount of times. Adding more than one test to be executed allows the comparison between several parts of a program, or different implementations.
eina_benchmark_run() runs all the tests registered with eina_benchmark_register(). The amount of time of each test is written in a gnuplot file.
For more information, you can look at the Benchmark Tutorial.
Define Documentation
#define EINA_BENCHMARK | ( | function | ) | ((Eina_Benchmark_Specimens)function) |
cast to an Eina_Benchmark_Specimens.
- Parameters:
-
function The function to cast.
This macro casts function
to Eina_Benchmark_Specimens.
Function Documentation
Eina_Benchmark * eina_benchmark_new | ( | const char * | name, | |
const char * | run | |||
) |
Create a new array.
- Parameters:
-
name The name of the benchmark. run The name of the run.
- Returns:
NULL
on failure, nonNULL
otherwise.
This function creates a new benchmark. name
and run
are used to name the gnuplot file that eina_benchmark_run() will create.
This function return a valid benchmark on success, or NULL
if memory allocation fails. In that case, the error is set to EINA_ERROR_OUT_OF_MEMORY.
When the new module is not needed anymore, use eina_benchmark_free() to free the allocated memory.
void eina_benchmark_free | ( | Eina_Benchmark * | bench | ) |
Free a benchmark object.
- Parameters:
-
bench The benchmark to free.
This function removes all the benchmark tests that have been registered and frees bench
. If bench
is NULL
, this function returns immediately.
Eina_Bool eina_benchmark_register | ( | Eina_Benchmark * | bench, | |
const char * | name, | |||
Eina_Benchmark_Specimens | bench_cb, | |||
int | count_start, | |||
int | count_end, | |||
int | count_step | |||
) |
Add a test to a benchmark.
- Parameters:
-
bench The benchmark. name The name of the test. bench_cb The test function to be called. count_start The start data to be passed to bench_cb
.count_end The end data to be passed to bench_cb
.count_step The step data to be passed to bench_cb
.
- Returns:
- EINA_FALSE on failure, EINA_TRUE otherwise.
This function adds the test named name
to benchmark
. bench_cb
is the function called when the test is executed. That test can be executed a certain amount of time. start
, end
and step
define a loop with a step increment. The integer that is increasing by step
from start
to end
is passed to bench_cb
when eina_benchmark_run() is called.
If bench
is NULL
, this function returns imediatly. If the allocation of the memory of the test to add fails, the error is set to EINA_ERROR_OUT_OF_MEMORY. This function returns EINA_FALSE on failure, EINA_TRUE otherwise.
Eina_Array * eina_benchmark_run | ( | Eina_Benchmark * | bench | ) |
Run the benchmark tests that have been registered.
- Parameters:
-
bench The benchmark.
- Returns:
- The list of names of the test files.
This function runs all the tests that as been registered with eina_benchmark_register() and save the result in a gnuplot file. The name of the file has the following format:
bench_[name]_[run]%s.gnuplot
where [name] and [run] are the values passed to eina_benchmark_new().
Each registered test is executed and timed. The time is written to the gnuplot file. The number of times each test is executed is controlled by the parameters passed to eina_benchmark_register().
If bench
is NULL
, this functions returns NULL
immediately. Otherwise, it returns the list of the names of each test.