benchmarks: better formatted output(use markdown)
This commit is contained in:
parent
8ca22bbf4c
commit
abbcbb6fbe
@ -19,12 +19,15 @@
|
||||
#include <assimp/Exporter.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/cimport.h>
|
||||
#include <assimp/version.h>
|
||||
|
||||
#include <gmio_core/error.h>
|
||||
#include <gmio_stl/stl_io.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
static unsigned totalTriangleCount(const aiScene* scene)
|
||||
{
|
||||
@ -48,26 +51,37 @@ GMIO_INLINE void copy_aiVector3D(
|
||||
*coords = *((gmio_stl_coords_t*)&vec3);
|
||||
}
|
||||
|
||||
namespace BenchmarkAssimp {
|
||||
namespace BmkAssimp {
|
||||
|
||||
static std::string assimp_version_str()
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Assimp v"
|
||||
<< aiGetVersionMajor() << '.'
|
||||
<< aiGetVersionMinor()
|
||||
<< ".?";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
Assimp::Importer* globalImporter = NULL;
|
||||
const aiScene* globalScene = NULL;
|
||||
|
||||
static void bmk_import(const char* filepath)
|
||||
static void import(const char* filepath)
|
||||
{
|
||||
Assimp::Importer* importer = globalImporter;
|
||||
const aiScene* scene = importer->ReadFile(filepath, 0);
|
||||
if (aiGetErrorString() != NULL)
|
||||
std::cerr << aiGetErrorString() << std::endl;
|
||||
const char* aiErrorStr = aiGetErrorString();
|
||||
if (std::strlen(aiErrorStr) > 0)
|
||||
std::cerr << aiErrorStr << std::endl;
|
||||
if (scene == NULL || scene->mNumMeshes <= 0) {
|
||||
std::cerr << "Failed to read file " << filepath << std::endl;
|
||||
}
|
||||
globalScene = scene;
|
||||
std::cout << "BenchAssimp, triCount = "
|
||||
<< totalTriangleCount(scene) << std::endl;
|
||||
// std::cout << "BmkAssimp, triCount = "
|
||||
// << totalTriangleCount(scene) << std::endl;
|
||||
}
|
||||
|
||||
static void bmk_export_stla(const char* filepath)
|
||||
static void export_stla(const char* filepath)
|
||||
{
|
||||
Assimp::Exporter exporter;
|
||||
// for (std::size_t i = 0; i < exporter.GetExportFormatCount(); ++i) {
|
||||
@ -78,32 +92,15 @@ static void bmk_export_stla(const char* filepath)
|
||||
exporter.Export(globalScene, "stl", filepath);
|
||||
}
|
||||
|
||||
static void bmk_export_stlb(const char* filepath)
|
||||
static void export_stlb(const char* filepath)
|
||||
{
|
||||
Assimp::Exporter exporter;
|
||||
exporter.Export(globalScene, "stlb", filepath);
|
||||
}
|
||||
|
||||
static void bmk_main(const char* filepath)
|
||||
{
|
||||
BenchmarkAssimp::globalImporter = new Assimp::Importer;
|
||||
benchmark(BenchmarkAssimp::bmk_import,
|
||||
"Assimp::Importer::ReadFile()",
|
||||
filepath);
|
||||
benchmark(BenchmarkAssimp::bmk_export_stla,
|
||||
"Assimp::Exporter::Export(STL_ASCII)",
|
||||
"__file_bench_assimp.stla");
|
||||
benchmark(BenchmarkAssimp::bmk_export_stlb,
|
||||
"Assimp::Exporter::Export(STL_BINARY)",
|
||||
"__file_bench_assimp.stlb");
|
||||
} // namespace BmkAssimp
|
||||
|
||||
delete BenchmarkAssimp::globalImporter;
|
||||
BenchmarkAssimp::globalImporter = NULL;
|
||||
}
|
||||
|
||||
} // namespace BenchAssimp
|
||||
|
||||
namespace BenchmarkGmio {
|
||||
namespace BmkGmio {
|
||||
|
||||
struct aiSceneHelper
|
||||
{
|
||||
@ -112,7 +109,7 @@ struct aiSceneHelper
|
||||
int hasToCountTriangle;
|
||||
};
|
||||
|
||||
aiSceneHelper globalSceneHelper = { 0 };
|
||||
aiSceneHelper globalSceneHelper = {};
|
||||
|
||||
static void allocate_stl_scene(aiScene* pScene)
|
||||
{
|
||||
@ -281,7 +278,7 @@ static void get_triangle(
|
||||
copy_aiVector3D(&triangle->v3, mesh->mVertices[f.mIndices[2]]);
|
||||
}
|
||||
|
||||
static void bmk_stl_read(const char* filepath)
|
||||
static void stl_read(const char* filepath)
|
||||
{
|
||||
gmio_stl_mesh_creator_t mesh_creator = { 0 };
|
||||
mesh_creator.cookie = &globalSceneHelper;
|
||||
@ -295,11 +292,11 @@ static void bmk_stl_read(const char* filepath)
|
||||
printf("gmio error: 0x%X\n", error);
|
||||
|
||||
const aiScene* scene = globalSceneHelper.scene;
|
||||
std::cout << "BenchGmio, triCount = "
|
||||
<< totalTriangleCount(scene) << std::endl;
|
||||
// std::cout << "BmkGmio, triCount = "
|
||||
// << totalTriangleCount(scene) << std::endl;
|
||||
}
|
||||
|
||||
static void bmk_stl_write(const char* filepath, gmio_stl_format_t format)
|
||||
static void stl_write(const char* filepath, gmio_stl_format_t format)
|
||||
{
|
||||
const aiMesh* sceneMesh = globalSceneHelper.scene->mMeshes[0];
|
||||
|
||||
@ -316,50 +313,74 @@ static void bmk_stl_write(const char* filepath, gmio_stl_format_t format)
|
||||
printf("gmio error: 0x%X\n", error);
|
||||
}
|
||||
|
||||
static void bmk_stla_write(const char* filepath)
|
||||
static void stla_write(const char* filepath)
|
||||
{
|
||||
bmk_stl_write(filepath, GMIO_STL_FORMAT_ASCII);
|
||||
stl_write(filepath, GMIO_STL_FORMAT_ASCII);
|
||||
}
|
||||
|
||||
static void bmk_stlb_write_le(const char* filepath)
|
||||
static void stlb_write_le(const char* filepath)
|
||||
{
|
||||
bmk_stl_write(filepath, GMIO_STL_FORMAT_BINARY_LE);
|
||||
stl_write(filepath, GMIO_STL_FORMAT_BINARY_LE);
|
||||
}
|
||||
|
||||
static void bmk_stlb_write_be(const char* filepath)
|
||||
static void stlb_write_be(const char* filepath)
|
||||
{
|
||||
bmk_stl_write(filepath, GMIO_STL_FORMAT_BINARY_BE);
|
||||
stl_write(filepath, GMIO_STL_FORMAT_BINARY_BE);
|
||||
}
|
||||
|
||||
static void bmk_main(const char* filepath)
|
||||
} // namespace BmkGmio
|
||||
|
||||
static void bmk_init()
|
||||
{
|
||||
BenchmarkGmio::globalSceneHelper.scene = new aiScene;
|
||||
BenchmarkGmio::globalSceneHelper.totalTriangleCount = 0;
|
||||
|
||||
benchmark(BenchmarkGmio::bmk_stl_read,
|
||||
"gmio_stl_read()",
|
||||
filepath);
|
||||
benchmark(BenchmarkGmio::bmk_stla_write,
|
||||
"gmio_stl_write(STL_ASCII)",
|
||||
"__file_bench_gmio.stla");
|
||||
benchmark(BenchmarkGmio::bmk_stlb_write_le,
|
||||
"gmio_stl_write(STL_BINARY_LE)",
|
||||
"__file_bench_gmio_le.stlb");
|
||||
benchmark(BenchmarkGmio::bmk_stlb_write_be,
|
||||
"gmio_stl_write(STL_BINARY_BE)",
|
||||
"__file_bench_gmio_be.stlb");
|
||||
|
||||
delete BenchmarkGmio::globalSceneHelper.scene;
|
||||
BenchmarkGmio::globalSceneHelper.scene = NULL;
|
||||
BmkAssimp::globalImporter = new Assimp::Importer;
|
||||
BmkGmio::globalSceneHelper.scene = new aiScene;
|
||||
BmkGmio::globalSceneHelper.totalTriangleCount = 0;
|
||||
}
|
||||
|
||||
} // namespace BenchmarkGmio
|
||||
static void bmk_cleanup()
|
||||
{
|
||||
delete BmkAssimp::globalImporter;
|
||||
BmkAssimp::globalImporter = NULL;
|
||||
delete BmkGmio::globalSceneHelper.scene;
|
||||
BmkGmio::globalSceneHelper.scene = NULL;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc > 1) {
|
||||
benchmark_forward_list(BenchmarkAssimp::bmk_main, argc - 1, argv + 1);
|
||||
benchmark_forward_list(BenchmarkGmio::bmk_main, argc - 1, argv + 1);
|
||||
const char* filepath = argv[1];
|
||||
std::cout << std::endl << "Input file: " << filepath << std::endl;
|
||||
|
||||
/* Declare benchmarks */
|
||||
const benchmark_cmp_arg_t cmp_args[] = {
|
||||
{ "read",
|
||||
BmkGmio::stl_read, filepath,
|
||||
BmkAssimp::import, filepath },
|
||||
{ "write(ascii)",
|
||||
BmkGmio::stla_write, "__bmk_assimp_gmio.stla",
|
||||
BmkAssimp::export_stla, "__bmk_assimp.stla" },
|
||||
{ "write(binary/le)",
|
||||
BmkGmio::stlb_write_le, "__bmk_assimp_gmio.stlb_le",
|
||||
BmkAssimp::export_stlb, "__bmk_assimp.stlb_le" },
|
||||
{ "write(binary/be)",
|
||||
BmkGmio::stlb_write_be, "__bmk_assimp_gmio.stlb_be",
|
||||
NULL, NULL },
|
||||
{}
|
||||
};
|
||||
|
||||
/* Execute benchmarks */
|
||||
std::vector<benchmark_cmp_result_t> cmp_res_vec;
|
||||
cmp_res_vec.resize(sizeof(cmp_args) / sizeof(benchmark_cmp_arg_t) - 1);
|
||||
benchmark_cmp_batch(
|
||||
5, &cmp_args[0], &cmp_res_vec[0], &bmk_init, &bmk_cleanup);
|
||||
|
||||
/* Print results */
|
||||
const benchmark_cmp_result_array_t res_array = {
|
||||
&cmp_res_vec.at(0), cmp_res_vec.size() };
|
||||
const std::string assimp_ver = BmkAssimp::assimp_version_str();
|
||||
const benchmark_cmp_result_header_t header = { "gmio", assimp_ver.c_str() };
|
||||
benchmark_print_results(
|
||||
BENCHMARK_PRINT_FORMAT_MARKDOWN, header, res_array);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -31,11 +31,13 @@ static void dummy_process_triangle(
|
||||
const gmio_stl_triangle_t* triangle)
|
||||
{
|
||||
my_igeom_t* my_igeom = (my_igeom_t*)(cookie);
|
||||
GMIO_UNUSED(triangle_id);
|
||||
GMIO_UNUSED(triangle);
|
||||
if (my_igeom != NULL)
|
||||
++(my_igeom->facet_count);
|
||||
}
|
||||
|
||||
static void bench_gmio_stl_read(const char* filepath)
|
||||
static void bmk_gmio_stl_read(const char* filepath)
|
||||
{
|
||||
my_igeom_t cookie = {0};
|
||||
gmio_stl_mesh_creator_t mesh_creator = {0};
|
||||
@ -79,6 +81,7 @@ static void readwrite_ascii_begin_solid(
|
||||
{
|
||||
stl_readwrite_conv_t* rw_conv = (stl_readwrite_conv_t*)cookie;
|
||||
gmio_stream_t* stream = &rw_conv->trsf.stream;
|
||||
GMIO_UNUSED(stream_size);
|
||||
if (rw_conv->out_format == GMIO_STL_FORMAT_ASCII) {
|
||||
stream->func_write(stream->cookie, "solid ", 1, 6);
|
||||
stream->func_write(stream->cookie, solid_name, 1, strlen(solid_name));
|
||||
@ -159,7 +162,7 @@ static void readwrite_end_solid(void* cookie)
|
||||
}
|
||||
}
|
||||
|
||||
static void bench_gmio_stl_readwrite_conv(const char* filepath)
|
||||
static void bmk_gmio_stl_readwrite_conv(const char* filepath)
|
||||
{
|
||||
FILE* infile = fopen(filepath, "rb");
|
||||
FILE* outfile = fopen("_readwrite_conv.stl", "wb");
|
||||
@ -202,12 +205,36 @@ static void bench_gmio_stl_readwrite_conv(const char* filepath)
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc > 1) {
|
||||
benchmark_list(&bench_gmio_stl_read,
|
||||
"gmio_stl_read_file()",
|
||||
argc - 1, argv + 1);
|
||||
benchmark_list(&bench_gmio_stl_readwrite_conv,
|
||||
"gmio_stl_readwrite_conv()",
|
||||
argc - 1, argv + 1);
|
||||
const char* filepath = argv[1];
|
||||
|
||||
/* Declare benchmarks */
|
||||
benchmark_cmp_arg_t cmp_args[] = {
|
||||
{ "read_file()",
|
||||
bmk_gmio_stl_read, NULL,
|
||||
NULL, NULL },
|
||||
{ "readwrite_conv()",
|
||||
bmk_gmio_stl_readwrite_conv, NULL,
|
||||
NULL, NULL },
|
||||
{0}
|
||||
};
|
||||
const size_t cmp_count =
|
||||
sizeof(cmp_args) / sizeof(benchmark_cmp_arg_t) - 1;
|
||||
benchmark_cmp_result_t cmp_res[2] = {0};
|
||||
benchmark_cmp_result_array_t res_array = {0};
|
||||
const benchmark_cmp_result_header_t header = { "gmio", NULL };
|
||||
|
||||
cmp_args[0].func1_filepath = filepath;
|
||||
cmp_args[1].func1_filepath = filepath;
|
||||
|
||||
res_array.ptr = &cmp_res[0];
|
||||
res_array.count = cmp_count;
|
||||
|
||||
/* Execute benchmarks */
|
||||
benchmark_cmp_batch(5, &cmp_args[0], &cmp_res[0], NULL, NULL);
|
||||
|
||||
/* Print results */
|
||||
benchmark_print_results(
|
||||
BENCHMARK_PRINT_FORMAT_MARKDOWN, header, res_array);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <OSD_Path.hxx>
|
||||
#include <RWStl.hxx>
|
||||
#include <StlMesh_Mesh.hxx>
|
||||
#include <Standard_Version.hxx>
|
||||
|
||||
#include <gmio_core/error.h>
|
||||
#include <gmio_stl/stl_io.h>
|
||||
@ -23,49 +24,38 @@
|
||||
|
||||
#include "../commons/benchmark_tools.h"
|
||||
|
||||
namespace BenchmarkOcc {
|
||||
#include <vector>
|
||||
|
||||
namespace BmkOcc {
|
||||
|
||||
Handle_StlMesh_Mesh stlMesh;
|
||||
|
||||
static void bmk_RWStl_ReadFile(const char* filepath)
|
||||
static void RWStl_ReadFile(const char* filepath)
|
||||
{
|
||||
stlMesh = RWStl::ReadFile(OSD_Path(filepath));
|
||||
if (stlMesh.IsNull())
|
||||
printf("RWStl::ReadFile(): null mesh\n");
|
||||
}
|
||||
|
||||
static void bmk_RWStl_WriteAscii(const char* filepath)
|
||||
static void RWStl_WriteAscii(const char* filepath)
|
||||
{
|
||||
if (!RWStl::WriteAscii(stlMesh, OSD_Path(filepath)))
|
||||
printf("RWStl::WriteAscii() failure\n");
|
||||
}
|
||||
|
||||
static void bmk_RWStl_WriteBinary(const char* filepath)
|
||||
static void RWStl_WriteBinary(const char* filepath)
|
||||
{
|
||||
if (!RWStl::WriteBinary(stlMesh, OSD_Path(filepath)))
|
||||
printf("RWStl::WriteBinary() failure\n");
|
||||
}
|
||||
|
||||
static void bmk_main(const char* filepath)
|
||||
{
|
||||
benchmark(BenchmarkOcc::bmk_RWStl_ReadFile,
|
||||
"RWStl::ReadFile()",
|
||||
filepath);
|
||||
benchmark(BenchmarkOcc::bmk_RWStl_WriteAscii,
|
||||
"RWStl::WriteAscii",
|
||||
"__file_bench_occ.stla");
|
||||
benchmark(BenchmarkOcc::bmk_RWStl_WriteBinary,
|
||||
"RWStl::WriteBinary",
|
||||
"__file_bench_occ.stlb");
|
||||
}
|
||||
} // namespace BmkOcc
|
||||
|
||||
} // namespace BenchmarkOcc
|
||||
|
||||
namespace BenchmarkGmio {
|
||||
namespace BmkGmio {
|
||||
|
||||
Handle_StlMesh_Mesh stlMesh;
|
||||
|
||||
static void bmk_stl_read(const char* filepath)
|
||||
static void stl_read(const char* filepath)
|
||||
{
|
||||
stlMesh = new StlMesh_Mesh;
|
||||
gmio_stl_mesh_creator_t mesh_creator = gmio_stl_hnd_occmesh_creator(stlMesh);
|
||||
@ -74,7 +64,7 @@ static void bmk_stl_read(const char* filepath)
|
||||
printf("gmio error: 0x%X\n", error);
|
||||
}
|
||||
|
||||
static void bmk_stl_write(const char* filepath, gmio_stl_format_t format)
|
||||
static void stl_write(const char* filepath, gmio_stl_format_t format)
|
||||
{
|
||||
const gmio_occ_stl_mesh_domain_t occ_mesh_domain(stlMesh);
|
||||
const gmio_stl_mesh_t mesh = gmio_stl_occmesh(&occ_mesh_domain);
|
||||
@ -87,44 +77,58 @@ static void bmk_stl_write(const char* filepath, gmio_stl_format_t format)
|
||||
printf("gmio error: 0x%X\n", error);
|
||||
}
|
||||
|
||||
static void bmk_stla_write(const char* filepath)
|
||||
static void stla_write(const char* filepath)
|
||||
{
|
||||
bmk_stl_write(filepath, GMIO_STL_FORMAT_ASCII);
|
||||
stl_write(filepath, GMIO_STL_FORMAT_ASCII);
|
||||
}
|
||||
|
||||
static void bmk_stlb_write_le(const char* filepath)
|
||||
static void stlb_write_le(const char* filepath)
|
||||
{
|
||||
bmk_stl_write(filepath, GMIO_STL_FORMAT_BINARY_LE);
|
||||
stl_write(filepath, GMIO_STL_FORMAT_BINARY_LE);
|
||||
}
|
||||
|
||||
static void bmk_stlb_write_be(const char* filepath)
|
||||
static void stlb_write_be(const char* filepath)
|
||||
{
|
||||
bmk_stl_write(filepath, GMIO_STL_FORMAT_BINARY_BE);
|
||||
stl_write(filepath, GMIO_STL_FORMAT_BINARY_BE);
|
||||
}
|
||||
|
||||
static void bmk_main(const char* filepath)
|
||||
{
|
||||
benchmark(bmk_stl_read,
|
||||
"gmio_stl_read()",
|
||||
filepath);
|
||||
benchmark(bmk_stla_write,
|
||||
"gmio_stl_write(STL_ASCII)",
|
||||
"__file_bench_gmio.stla");
|
||||
benchmark(bmk_stlb_write_le,
|
||||
"gmio_stl_write(STL_BINARY_LE)",
|
||||
"__file_bench_gmio_le.stlb");
|
||||
benchmark(bmk_stlb_write_be,
|
||||
"gmio_stl_write(STL_BINARY_BE)",
|
||||
"__file_bench_gmio_be.stlb");
|
||||
}
|
||||
} // namespace BenchmarkGmio
|
||||
} // namespace BmkGmio
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc > 1) {
|
||||
benchmark_forward_list(BenchmarkOcc::bmk_main, argc - 1, argv + 1);
|
||||
benchmark_forward_list(BenchmarkGmio::bmk_main, argc - 1, argv + 1);
|
||||
}
|
||||
const char* filepath = argv[1];
|
||||
std::cout << std::endl << "Input file: " << filepath << std::endl;
|
||||
|
||||
/* Declare benchmarks */
|
||||
const benchmark_cmp_arg_t cmp_args[] = {
|
||||
{ "read",
|
||||
BmkGmio::stl_read, filepath,
|
||||
BmkOcc::RWStl_ReadFile, filepath },
|
||||
{ "write(ascii)",
|
||||
BmkGmio::stla_write, "__bmk_occ_gmio.stla",
|
||||
BmkOcc::RWStl_WriteAscii, "__bmk_occ.stla" },
|
||||
{ "write(binary/le)",
|
||||
BmkGmio::stlb_write_le, "__bmk_occ_gmio.stlb_le",
|
||||
BmkOcc::RWStl_WriteBinary, "__bmk_occ.stlb_le" },
|
||||
{ "write(binary/be)",
|
||||
BmkGmio::stlb_write_be, "__bmk_occ_gmio.stlb_be",
|
||||
NULL, NULL },
|
||||
{}
|
||||
};
|
||||
|
||||
/* Execute benchmarks */
|
||||
std::vector<benchmark_cmp_result_t> cmp_res_vec;
|
||||
cmp_res_vec.resize(sizeof(cmp_args) / sizeof(benchmark_cmp_arg_t) - 1);
|
||||
benchmark_cmp_batch(5, &cmp_args[0], &cmp_res_vec[0], NULL, NULL);
|
||||
|
||||
/* Print results */
|
||||
const benchmark_cmp_result_array_t res_array = {
|
||||
&cmp_res_vec.at(0), cmp_res_vec.size() };
|
||||
const benchmark_cmp_result_header_t header = {
|
||||
"gmio", "OpenCascade v"OCC_VERSION_COMPLETE };
|
||||
benchmark_print_results(
|
||||
BENCHMARK_PRINT_FORMAT_MARKDOWN, header, res_array);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -16,11 +16,13 @@
|
||||
#include "benchmark_tools.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef WIN32
|
||||
# include <windows.h>
|
||||
# define BENCHMARK_TIMER_WINDOWS
|
||||
#else
|
||||
# include <time.h>
|
||||
# define BENCHMARK_TIMER_LIBC
|
||||
#endif
|
||||
|
||||
@ -34,7 +36,7 @@ typedef struct benchmark_timer
|
||||
#endif
|
||||
} benchmark_timer_t;
|
||||
|
||||
void benchmark_timer_start(benchmark_timer_t* timer)
|
||||
static void benchmark_timer_start(benchmark_timer_t* timer)
|
||||
{
|
||||
#ifdef BENCHMARK_TIMER_WINDOWS
|
||||
QueryPerformanceFrequency(&timer->frequency);
|
||||
@ -44,11 +46,11 @@ void benchmark_timer_start(benchmark_timer_t* timer)
|
||||
#endif
|
||||
}
|
||||
|
||||
int64_t benchmark_timer_elapsed_ms(const benchmark_timer_t* timer)
|
||||
static int64_t benchmark_timer_elapsed_ms(const benchmark_timer_t* timer)
|
||||
{
|
||||
#ifdef BENCHMARK_TIMER_WINDOWS
|
||||
LARGE_INTEGER end_time = { 0 };
|
||||
LARGE_INTEGER elapsed = { 0 };
|
||||
LARGE_INTEGER end_time = {0};
|
||||
LARGE_INTEGER elapsed = {0};
|
||||
QueryPerformanceCounter(&end_time);
|
||||
elapsed.QuadPart = end_time.QuadPart - timer->start_time.QuadPart;
|
||||
|
||||
@ -70,37 +72,124 @@ int64_t benchmark_timer_elapsed_ms(const benchmark_timer_t* timer)
|
||||
#endif
|
||||
}
|
||||
|
||||
void benchmark_list(
|
||||
benchmark_file_func_t func, const char* title, int argc, char **argv)
|
||||
benchmark_cmp_result_t benchmark_cmp(benchmark_cmp_arg_t arg)
|
||||
{
|
||||
benchmark_timer_t timer = { 0 };
|
||||
int iarg;
|
||||
benchmark_cmp_result_t result = {0};
|
||||
result.tag = arg.tag;
|
||||
|
||||
if (func == NULL)
|
||||
return;
|
||||
|
||||
benchmark_timer_start(&timer);
|
||||
|
||||
printf("Bench %s ...\n", title);
|
||||
for (iarg = 0; iarg < argc; ++iarg) {
|
||||
printf(" File %s ...\n", argv[iarg]);
|
||||
(*func)(argv[iarg]);
|
||||
if (arg.func1 != NULL) {
|
||||
benchmark_timer_t timer = {0};
|
||||
benchmark_timer_start(&timer);
|
||||
(*arg.func1)(arg.func1_filepath);
|
||||
result.func1_exec_time_ms = benchmark_timer_elapsed_ms(&timer);
|
||||
result.has_func1_exec_time = GMIO_TRUE;
|
||||
}
|
||||
/*printf(" exec time: %.2fs\n\n", elapsed_secs(start_tick));*/
|
||||
printf(" exec time: %lldms\n\n", benchmark_timer_elapsed_ms(&timer));
|
||||
if (arg.func2 != NULL) {
|
||||
benchmark_timer_t timer = {0};
|
||||
benchmark_timer_start(&timer);
|
||||
(*arg.func2)(arg.func2_filepath);
|
||||
result.func2_exec_time_ms = benchmark_timer_elapsed_ms(&timer);
|
||||
result.has_func2_exec_time = GMIO_TRUE;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void benchmark_forward_list(benchmark_file_func_t func, int argc, char **argv)
|
||||
static void printf_string_n(const char* str, size_t n)
|
||||
{
|
||||
int i = 0;
|
||||
while (i < argc) {
|
||||
func(argv[i]);
|
||||
++i;
|
||||
size_t i; /* for-loop index*/
|
||||
for (i = 0; i < n; ++i)
|
||||
printf(str);
|
||||
}
|
||||
|
||||
static const int width_tag_col = 20;
|
||||
static const int width_func_col = 10;
|
||||
static const char* unit_time_str = "ms";
|
||||
|
||||
static void printf_func_exec_time(
|
||||
size_t func_exec_time_ms, gmio_bool_t has_func_exec_time)
|
||||
{
|
||||
if (has_func_exec_time) {
|
||||
char str_exec_time[128] = {0};
|
||||
/* TODO: %ull is not accepted by mingw, find a fix(maybe %ul64) */
|
||||
sprintf(str_exec_time, "%u%s", func_exec_time_ms, unit_time_str);
|
||||
printf("%-*s", width_func_col, str_exec_time);
|
||||
}
|
||||
else {
|
||||
printf("%-*s", width_func_col, "N/A");
|
||||
}
|
||||
}
|
||||
|
||||
void benchmark(
|
||||
benchmark_file_func_t func, const char *title, const char* filepath)
|
||||
void benchmark_print_results(
|
||||
benchmark_print_format_t format,
|
||||
benchmark_cmp_result_header_t header,
|
||||
benchmark_cmp_result_array_t result_array)
|
||||
{
|
||||
benchmark_list(func, title, 1, (char**)&filepath);
|
||||
if (format == BENCHMARK_PRINT_FORMAT_MARKDOWN) {
|
||||
size_t i; /* for-loop index*/
|
||||
|
||||
/* Print table header */
|
||||
printf("%*s | ", width_tag_col, "");
|
||||
printf("%-*s | ", width_func_col, header.component_1);
|
||||
printf("%-*s\n", width_func_col, header.component_2);
|
||||
|
||||
/* Print separation between header and results */
|
||||
printf_string_n("-", width_tag_col + 1);
|
||||
printf("|");
|
||||
printf_string_n("-", width_func_col + strlen(unit_time_str));
|
||||
printf("|");
|
||||
printf_string_n("-", width_func_col + strlen(unit_time_str));
|
||||
printf("\n");
|
||||
|
||||
/* Print benchmark result lines */
|
||||
for (i = 0; i < result_array.count; ++i) {
|
||||
const benchmark_cmp_result_t result = result_array.ptr[i];
|
||||
printf("%-*s | ", width_tag_col, result.tag);
|
||||
printf_func_exec_time(
|
||||
result.func1_exec_time_ms, result.has_func1_exec_time);
|
||||
printf(" | ");
|
||||
printf_func_exec_time(
|
||||
result.func2_exec_time_ms, result.has_func2_exec_time);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void benchmark_cmp_batch(
|
||||
size_t run_count,
|
||||
const benchmark_cmp_arg_t *arg_array,
|
||||
benchmark_cmp_result_t *result_array,
|
||||
void (*func_init)(),
|
||||
void (*func_cleanup)())
|
||||
{
|
||||
size_t run; /* for-loop index */
|
||||
size_t array_size = 0;
|
||||
while (arg_array[array_size].tag != NULL) {
|
||||
++array_size;
|
||||
}
|
||||
|
||||
for (run = 0; run < run_count; ++run) {
|
||||
size_t i; /* for-loop index */
|
||||
/* Init */
|
||||
if (func_init)
|
||||
(*func_init)();
|
||||
|
||||
for (i = 0; i < array_size; ++i) {
|
||||
const benchmark_cmp_result_t ires = benchmark_cmp(arg_array[i]);
|
||||
benchmark_cmp_result_t* fres = &result_array[i];
|
||||
if (run != 0) {
|
||||
if (fres->func1_exec_time_ms > ires.func1_exec_time_ms)
|
||||
fres->func1_exec_time_ms = ires.func1_exec_time_ms;
|
||||
if (fres->func2_exec_time_ms > ires.func2_exec_time_ms)
|
||||
fres->func2_exec_time_ms = ires.func2_exec_time_ms;
|
||||
}
|
||||
else {
|
||||
*fres = ires;
|
||||
}
|
||||
}
|
||||
|
||||
/* Cleanup */
|
||||
if (func_cleanup)
|
||||
(*func_cleanup)();
|
||||
}
|
||||
}
|
||||
|
@ -22,14 +22,64 @@ GMIO_C_LINKAGE_BEGIN
|
||||
|
||||
typedef void (*benchmark_file_func_t)(const char*);
|
||||
|
||||
void benchmark_list(
|
||||
benchmark_file_func_t func, const char* title, int argc, char** argv);
|
||||
/* benchmark_cmp */
|
||||
|
||||
void benchmark_forward_list(
|
||||
benchmark_file_func_t func, int argc, char** argv);
|
||||
struct benchmark_cmp_arg
|
||||
{
|
||||
const char* tag;
|
||||
benchmark_file_func_t func1;
|
||||
const char* func1_filepath;
|
||||
benchmark_file_func_t func2;
|
||||
const char* func2_filepath;
|
||||
};
|
||||
typedef struct benchmark_cmp_arg benchmark_cmp_arg_t;
|
||||
|
||||
void benchmark(
|
||||
benchmark_file_func_t func, const char* title, const char* filepath);
|
||||
struct benchmark_cmp_result
|
||||
{
|
||||
const char* tag;
|
||||
size_t func1_exec_time_ms;
|
||||
gmio_bool_t has_func1_exec_time;
|
||||
size_t func2_exec_time_ms;
|
||||
gmio_bool_t has_func2_exec_time;
|
||||
};
|
||||
typedef struct benchmark_cmp_result benchmark_cmp_result_t;
|
||||
|
||||
benchmark_cmp_result_t benchmark_cmp(benchmark_cmp_arg_t arg);
|
||||
|
||||
void benchmark_cmp_batch(
|
||||
size_t run_count,
|
||||
const benchmark_cmp_arg_t* arg_array,
|
||||
benchmark_cmp_result_t* result_array,
|
||||
void (*func_init)(),
|
||||
void (*func_cleanup)());
|
||||
|
||||
|
||||
/* benchmark_print_results */
|
||||
|
||||
enum benchmark_print_format
|
||||
{
|
||||
BENCHMARK_PRINT_FORMAT_MARKDOWN = 0
|
||||
};
|
||||
typedef enum benchmark_print_format benchmark_print_format_t;
|
||||
|
||||
struct benchmark_cmp_result_array
|
||||
{
|
||||
const benchmark_cmp_result_t* ptr;
|
||||
size_t count;
|
||||
};
|
||||
typedef struct benchmark_cmp_result_array benchmark_cmp_result_array_t;
|
||||
|
||||
struct benchmark_cmp_result_header
|
||||
{
|
||||
const char* component_1;
|
||||
const char* component_2;
|
||||
};
|
||||
typedef struct benchmark_cmp_result_header benchmark_cmp_result_header_t;
|
||||
|
||||
void benchmark_print_results(
|
||||
benchmark_print_format_t format,
|
||||
benchmark_cmp_result_header_t header,
|
||||
benchmark_cmp_result_array_t result_array);
|
||||
|
||||
GMIO_C_LINKAGE_END
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user