2015-09-01 23:01:38 +08:00
|
|
|
/****************************************************************************
|
|
|
|
** gmio benchmarks
|
|
|
|
** Copyright Fougue (2 Mar. 2015)
|
|
|
|
** contact@fougue.pro
|
|
|
|
**
|
|
|
|
** This software provides performance benchmarks for the gmio library
|
|
|
|
** (https://github.com/fougue/gmio)
|
|
|
|
**
|
|
|
|
** This software is governed by the CeCILL-B license under French law and
|
|
|
|
** abiding by the rules of distribution of free software. You can use,
|
|
|
|
** modify and/ or redistribute the software under the terms of the CeCILL-B
|
|
|
|
** license as circulated by CEA, CNRS and INRIA at the following URL
|
|
|
|
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-09-01 23:30:49 +08:00
|
|
|
#ifndef BENCHMARK_TOOLS_H
|
|
|
|
#define BENCHMARK_TOOLS_H
|
2015-09-01 23:01:38 +08:00
|
|
|
|
2016-01-12 23:30:24 +08:00
|
|
|
#include "../../src/gmio_core/global.h"
|
2015-09-24 01:28:04 +08:00
|
|
|
#include <stddef.h>
|
2015-09-01 23:01:38 +08:00
|
|
|
|
|
|
|
GMIO_C_LINKAGE_BEGIN
|
|
|
|
|
2015-11-06 20:40:15 +08:00
|
|
|
#ifdef GMIO_HAVE_INT64_TYPE
|
|
|
|
typedef uint64_t gmio_time_ms_t;
|
|
|
|
#else
|
|
|
|
typedef size_t gmio_time_ms_t;
|
|
|
|
#endif
|
|
|
|
|
2015-10-28 21:56:52 +08:00
|
|
|
/*! Typedef on pointer to function to be benchmarked(execution time) */
|
2016-01-13 00:37:45 +08:00
|
|
|
typedef void (*benchmark_func_t)(const void*);
|
2015-09-01 23:01:38 +08:00
|
|
|
|
2015-09-23 21:30:17 +08:00
|
|
|
/* benchmark_cmp */
|
2015-09-01 23:01:38 +08:00
|
|
|
|
2015-10-28 21:56:52 +08:00
|
|
|
/*! Describes a comparison benchmark between two functions */
|
2015-09-23 21:30:17 +08:00
|
|
|
struct benchmark_cmp_arg
|
|
|
|
{
|
2015-10-28 21:56:52 +08:00
|
|
|
/*! Brief description of the comparison(eg. "Write to file") */
|
2015-09-23 21:30:17 +08:00
|
|
|
const char* tag;
|
2015-10-28 21:56:52 +08:00
|
|
|
/*! Pointer to the 1st function */
|
2016-01-13 00:37:45 +08:00
|
|
|
benchmark_func_t func1;
|
2015-10-28 21:56:52 +08:00
|
|
|
/*! Argument passed to the 1st function on exec */
|
2016-01-13 00:37:45 +08:00
|
|
|
const void* func1_arg;
|
2015-10-28 21:56:52 +08:00
|
|
|
/*! Pointer to the 2nd function */
|
2016-01-13 00:37:45 +08:00
|
|
|
benchmark_func_t func2;
|
2015-10-28 21:56:52 +08:00
|
|
|
/*! Argument passed to the 2nd function on exec */
|
2016-01-13 00:37:45 +08:00
|
|
|
const void* func2_arg;
|
2015-09-23 21:30:17 +08:00
|
|
|
};
|
2015-09-01 23:01:38 +08:00
|
|
|
|
2015-10-28 21:56:52 +08:00
|
|
|
/*! Holds the result of the exec time comparison between two functions */
|
2015-09-23 21:30:17 +08:00
|
|
|
struct benchmark_cmp_result
|
|
|
|
{
|
2015-10-28 21:56:52 +08:00
|
|
|
/*! Identifies the comparison */
|
2015-09-23 21:30:17 +08:00
|
|
|
const char* tag;
|
2015-10-28 21:56:52 +08:00
|
|
|
/*! Execution time(in ms) of the 1st function */
|
2015-11-06 20:40:15 +08:00
|
|
|
gmio_time_ms_t func1_exec_time_ms;
|
2015-10-28 21:56:52 +08:00
|
|
|
/*! Is exec time of the 1st function valid ? */
|
2016-01-27 00:03:58 +08:00
|
|
|
bool has_func1_exec_time;
|
2015-10-28 21:56:52 +08:00
|
|
|
/*! Execution time(in ms) of the 2nd function */
|
2015-11-06 20:40:15 +08:00
|
|
|
gmio_time_ms_t func2_exec_time_ms;
|
2015-10-28 21:56:52 +08:00
|
|
|
/*! Is exec time of the 2nd function valid ? */
|
2016-01-27 00:03:58 +08:00
|
|
|
bool has_func2_exec_time;
|
2015-10-28 23:03:31 +08:00
|
|
|
float func2_func1_ratio;
|
2015-09-23 21:30:17 +08:00
|
|
|
};
|
|
|
|
|
2015-10-28 21:56:52 +08:00
|
|
|
/*! Runs func1 then func2 and measures the respective execution time */
|
2015-12-04 01:00:25 +08:00
|
|
|
struct benchmark_cmp_result benchmark_cmp(struct benchmark_cmp_arg arg);
|
2015-09-23 21:30:17 +08:00
|
|
|
|
2015-10-28 21:56:52 +08:00
|
|
|
/*! Runs a batch(array) of comparison benchmarks */
|
2015-09-23 21:30:17 +08:00
|
|
|
void benchmark_cmp_batch(
|
|
|
|
size_t run_count,
|
2015-12-04 01:00:25 +08:00
|
|
|
const struct benchmark_cmp_arg* arg_array,
|
|
|
|
struct benchmark_cmp_result* result_array,
|
2015-09-23 21:30:17 +08:00
|
|
|
void (*func_init)(),
|
|
|
|
void (*func_cleanup)());
|
|
|
|
|
|
|
|
|
|
|
|
/* benchmark_print_results */
|
|
|
|
|
|
|
|
enum benchmark_print_format
|
|
|
|
{
|
|
|
|
BENCHMARK_PRINT_FORMAT_MARKDOWN = 0
|
|
|
|
};
|
|
|
|
|
2015-10-28 21:56:52 +08:00
|
|
|
/*! Array of benchmark_cmp_result */
|
2015-09-23 21:30:17 +08:00
|
|
|
struct benchmark_cmp_result_array
|
|
|
|
{
|
2015-12-04 01:00:25 +08:00
|
|
|
const struct benchmark_cmp_result* ptr;
|
2015-09-23 21:30:17 +08:00
|
|
|
size_t count;
|
|
|
|
};
|
|
|
|
|
2015-10-28 21:56:52 +08:00
|
|
|
/*! Horizontal header labels for benchmark results(by column) */
|
2015-09-23 21:30:17 +08:00
|
|
|
struct benchmark_cmp_result_header
|
|
|
|
{
|
|
|
|
const char* component_1;
|
|
|
|
const char* component_2;
|
|
|
|
};
|
|
|
|
|
2015-10-28 21:56:52 +08:00
|
|
|
/*! Prints formatted benchmark results */
|
2015-09-23 21:30:17 +08:00
|
|
|
void benchmark_print_results(
|
2015-12-04 01:00:25 +08:00
|
|
|
enum benchmark_print_format format,
|
|
|
|
struct benchmark_cmp_result_header header,
|
|
|
|
struct benchmark_cmp_result_array result_array);
|
2015-09-01 23:01:38 +08:00
|
|
|
|
|
|
|
GMIO_C_LINKAGE_END
|
|
|
|
|
2015-09-01 23:30:49 +08:00
|
|
|
#endif /* BENCHMARK_TOOLS_H */
|