gmio/benchmarks/commons/benchmark_tools.h

119 lines
3.9 KiB
C
Raw Normal View History

2015-09-01 23:01:38 +08:00
/****************************************************************************
2017-01-27 01:05:12 +08:00
** Copyright (c) 2017, Fougue Ltd. <http://www.fougue.pro>
2016-07-05 18:46:22 +08:00
** All rights reserved.
2015-09-01 23:01:38 +08:00
**
2016-07-05 18:46:22 +08:00
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
2015-09-01 23:01:38 +08:00
**
2016-07-05 18:46:22 +08:00
** 1. Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
**
** 2. Redistributions in binary form must reproduce the above
** copyright notice, this list of conditions and the following
** disclaimer in the documentation and/or other materials provided
** with the distribution.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2015-09-01 23:01:38 +08:00
****************************************************************************/
2017-01-30 18:41:20 +08:00
#pragma once
2015-09-01 23:01:38 +08:00
#include "../../src/gmio_core/global.h"
#include <stddef.h>
2015-09-01 23:01:38 +08:00
GMIO_C_LINKAGE_BEGIN
#ifdef GMIO_HAVE_INT64_TYPE
typedef uint64_t gmio_time_ms_t;
#else
typedef size_t gmio_time_ms_t;
#endif
/*! Typedef on pointer to function to be benchmarked(execution time) */
typedef void (*benchmark_func_t)(const void*);
2015-09-01 23:01:38 +08:00
/* benchmark_cmp */
2015-09-01 23:01:38 +08:00
/*! Describes a comparison benchmark between two functions */
struct benchmark_cmp_arg
{
/*! Brief description of the comparison(eg. "Write to file") */
const char* tag;
/*! Pointer to the 1st function */
benchmark_func_t func1;
/*! Argument passed to the 1st function on exec */
const void* func1_arg;
/*! Pointer to the 2nd function */
benchmark_func_t func2;
/*! Argument passed to the 2nd function on exec */
const void* func2_arg;
};
2015-09-01 23:01:38 +08:00
/*! Holds the result of the exec time comparison between two functions */
struct benchmark_cmp_result
{
/*! Identifies the comparison */
const char* tag;
/*! Execution time(in ms) of the 1st function */
gmio_time_ms_t func1_exec_time_ms;
/*! Is exec time of the 1st function valid ? */
2016-01-27 00:03:58 +08:00
bool has_func1_exec_time;
/*! Execution time(in ms) of the 2nd function */
gmio_time_ms_t func2_exec_time_ms;
/*! 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;
};
/*! Runs func1 then func2 and measures the respective execution time */
struct benchmark_cmp_result benchmark_cmp(struct benchmark_cmp_arg arg);
/*! Runs a batch(array) of comparison benchmarks */
void benchmark_cmp_batch(
size_t run_count,
const struct benchmark_cmp_arg* arg_array,
struct benchmark_cmp_result* result_array,
void (*func_init)(),
void (*func_cleanup)());
/* benchmark_print_results */
enum benchmark_print_format
{
BENCHMARK_PRINT_FORMAT_MARKDOWN = 0
};
/*! Array of benchmark_cmp_result */
struct benchmark_cmp_result_array
{
const struct benchmark_cmp_result* ptr;
size_t count;
};
/*! Horizontal header labels for benchmark results(by column) */
struct benchmark_cmp_result_header
{
const char* component_1;
const char* component_2;
};
/*! Prints formatted benchmark results */
void benchmark_print_results(
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