benchmarks: give void* instead of char* to benchmark functions

This commit is contained in:
Hugues Delorme 2016-01-12 17:37:45 +01:00
parent 8c5aea272f
commit 351bb6cafc
6 changed files with 45 additions and 42 deletions

View File

@ -70,10 +70,11 @@ static std::string assimp_version_str()
Assimp::Importer* globalImporter = NULL; Assimp::Importer* globalImporter = NULL;
const aiScene* globalScene = NULL; const aiScene* globalScene = NULL;
static void import(const char* filepath) static void import(const void* filepath)
{ {
Assimp::Importer* importer = globalImporter; Assimp::Importer* importer = globalImporter;
const aiScene* scene = importer->ReadFile(filepath, 0); const aiScene* scene =
importer->ReadFile(static_cast<const char*>(filepath), 0);
const char* aiErrorStr = aiGetErrorString(); const char* aiErrorStr = aiGetErrorString();
if (std::strlen(aiErrorStr) > 0) if (std::strlen(aiErrorStr) > 0)
std::cerr << aiErrorStr << std::endl; std::cerr << aiErrorStr << std::endl;
@ -85,7 +86,7 @@ static void import(const char* filepath)
// << totalTriangleCount(scene) << std::endl; // << totalTriangleCount(scene) << std::endl;
} }
static void export_stla(const char* filepath) static void export_stla(const void* filepath)
{ {
Assimp::Exporter exporter; Assimp::Exporter exporter;
// for (std::size_t i = 0; i < exporter.GetExportFormatCount(); ++i) { // for (std::size_t i = 0; i < exporter.GetExportFormatCount(); ++i) {
@ -93,13 +94,13 @@ static void export_stla(const char* filepath)
// << exporter.GetExportFormatDescription(i)->description // << exporter.GetExportFormatDescription(i)->description
// << std::endl; // << std::endl;
// } // }
exporter.Export(globalScene, "stl", filepath); exporter.Export(globalScene, "stl", static_cast<const char*>(filepath));
} }
static void export_stlb(const char* filepath) static void export_stlb(const void* filepath)
{ {
Assimp::Exporter exporter; Assimp::Exporter exporter;
exporter.Export(globalScene, "stlb", filepath); exporter.Export(globalScene, "stlb", static_cast<const char*>(filepath));
} }
} // namespace BmkAssimp } // namespace BmkAssimp
@ -282,7 +283,7 @@ static void get_triangle(
copy_aiVector3D(&triangle->v3, mesh->mVertices[f.mIndices[2]]); copy_aiVector3D(&triangle->v3, mesh->mVertices[f.mIndices[2]]);
} }
static void stl_read(const char* filepath) static void stl_read(const void* filepath)
{ {
gmio_stl_read_args read = {}; gmio_stl_read_args read = {};
read.mesh_creator.cookie = &globalSceneHelper; read.mesh_creator.cookie = &globalSceneHelper;
@ -291,7 +292,8 @@ static void stl_read(const char* filepath)
read.mesh_creator.func_add_triangle = add_triangle; read.mesh_creator.func_add_triangle = add_triangle;
read.mesh_creator.func_end_solid = end_solid; read.mesh_creator.func_end_solid = end_solid;
const int error = gmio_stl_read_file(&read, filepath); const int error =
gmio_stl_read_file(&read, static_cast<const char*>(filepath));
if (error != GMIO_ERROR_OK) if (error != GMIO_ERROR_OK)
printf("gmio error: 0x%X\n", error); printf("gmio error: 0x%X\n", error);
@ -315,19 +317,19 @@ static void stl_write(const char* filepath, gmio_stl_format format)
printf("gmio error: 0x%X\n", error); printf("gmio error: 0x%X\n", error);
} }
static void stla_write(const char* filepath) static void stla_write(const void* filepath)
{ {
stl_write(filepath, GMIO_STL_FORMAT_ASCII); stl_write(static_cast<const char*>(filepath), GMIO_STL_FORMAT_ASCII);
} }
static void stlb_write_le(const char* filepath) static void stlb_write_le(const void* filepath)
{ {
stl_write(filepath, GMIO_STL_FORMAT_BINARY_LE); stl_write(static_cast<const char*>(filepath), GMIO_STL_FORMAT_BINARY_LE);
} }
static void stlb_write_be(const char* filepath) static void stlb_write_be(const void* filepath)
{ {
stl_write(filepath, GMIO_STL_FORMAT_BINARY_BE); stl_write(static_cast<const char*>(filepath), GMIO_STL_FORMAT_BINARY_BE);
} }
} // namespace BmkGmio } // namespace BmkGmio

View File

@ -44,7 +44,7 @@ static void dummy_process_triangle(
++(my_igeom->facet_count); ++(my_igeom->facet_count);
} }
static void bmk_gmio_stl_read(const char* filepath) static void bmk_gmio_stl_read(const void* filepath)
{ {
struct my_igeom cookie = {0}; struct my_igeom cookie = {0};
struct gmio_stl_read_args read = {0}; struct gmio_stl_read_args read = {0};
@ -170,7 +170,7 @@ static void readwrite_end_solid(void* cookie)
} }
} }
static void bmk_gmio_stl_readwrite_conv(const char* filepath) static void bmk_gmio_stl_readwrite_conv(const void* filepath)
{ {
FILE* infile = fopen(filepath, "rb"); FILE* infile = fopen(filepath, "rb");
FILE* outfile = fopen("_readwrite_conv.stl", "wb"); FILE* outfile = fopen("_readwrite_conv.stl", "wb");
@ -212,7 +212,7 @@ static void bmk_gmio_stl_readwrite_conv(const char* filepath)
fclose(outfile); fclose(outfile);
} }
void bmk_gmio_stl_infos_get(const char* filepath) void bmk_gmio_stl_infos_get(const void* filepath)
{ {
static gmio_bool_t already_exec = GMIO_FALSE; static gmio_bool_t already_exec = GMIO_FALSE;
FILE* file = fopen(filepath, "rb"); FILE* file = fopen(filepath, "rb");
@ -260,7 +260,7 @@ int main(int argc, char** argv)
{ {
size_t i = 0; size_t i = 0;
for (i = 0; i < cmp_count; ++i) for (i = 0; i < cmp_count; ++i)
cmp_args[i].func1_filepath = filepath; cmp_args[i].func1_arg = filepath;
} }
res_array.ptr = &cmp_res[0]; res_array.ptr = &cmp_res[0];

View File

@ -31,22 +31,22 @@ namespace BmkOcc {
Handle_StlMesh_Mesh stlMesh; Handle_StlMesh_Mesh stlMesh;
static void RWStl_ReadFile(const char* filepath) static void RWStl_ReadFile(const void* filepath)
{ {
stlMesh = RWStl::ReadFile(OSD_Path(filepath)); stlMesh = RWStl::ReadFile(OSD_Path(static_cast<const char*>(filepath)));
if (stlMesh.IsNull()) if (stlMesh.IsNull())
printf("RWStl::ReadFile(): null mesh\n"); printf("RWStl::ReadFile(): null mesh\n");
} }
static void RWStl_WriteAscii(const char* filepath) static void RWStl_WriteAscii(const void* filepath)
{ {
if (!RWStl::WriteAscii(stlMesh, OSD_Path(filepath))) if (!RWStl::WriteAscii(stlMesh, OSD_Path(static_cast<const char*>(filepath))))
printf("RWStl::WriteAscii() failure\n"); printf("RWStl::WriteAscii() failure\n");
} }
static void RWStl_WriteBinary(const char* filepath) static void RWStl_WriteBinary(const void* filepath)
{ {
if (!RWStl::WriteBinary(stlMesh, OSD_Path(filepath))) if (!RWStl::WriteBinary(stlMesh, OSD_Path(static_cast<const char*>(filepath))))
printf("RWStl::WriteBinary() failure\n"); printf("RWStl::WriteBinary() failure\n");
} }
@ -56,12 +56,12 @@ namespace BmkGmio {
Handle_StlMesh_Mesh stlMesh; Handle_StlMesh_Mesh stlMesh;
static void stl_read(const char* filepath) static void stl_read(const void* filepath)
{ {
stlMesh = new StlMesh_Mesh; stlMesh = new StlMesh_Mesh;
gmio_stl_read_args read = {}; gmio_stl_read_args read = {};
read.mesh_creator = gmio_stl_hnd_occmesh_creator(stlMesh); read.mesh_creator = gmio_stl_hnd_occmesh_creator(stlMesh);
int error = gmio_stl_read_file(&read, filepath); int error = gmio_stl_read_file(&read, static_cast<const char*>(filepath));
if (error != GMIO_ERROR_OK) if (error != GMIO_ERROR_OK)
printf("gmio error: 0x%X\n", error); printf("gmio error: 0x%X\n", error);
} }
@ -73,24 +73,25 @@ static void stl_write(const char* filepath, gmio_stl_format format)
write.mesh = gmio_stl_occmesh(&occ_mesh_domain); write.mesh = gmio_stl_occmesh(&occ_mesh_domain);
write.options.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_UPPERCASE; write.options.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_UPPERCASE;
write.options.stla_float32_prec = 7; write.options.stla_float32_prec = 7;
const int error = gmio_stl_write_file(&write, format, filepath); const int error =
gmio_stl_write_file(&write, format, static_cast<const char*>(filepath));
if (error != GMIO_ERROR_OK) if (error != GMIO_ERROR_OK)
printf("gmio error: 0x%X\n", error); printf("gmio error: 0x%X\n", error);
} }
static void stla_write(const char* filepath) static void stla_write(const void* filepath)
{ {
stl_write(filepath, GMIO_STL_FORMAT_ASCII); stl_write(static_cast<const char*>(filepath), GMIO_STL_FORMAT_ASCII);
} }
static void stlb_write_le(const char* filepath) static void stlb_write_le(const void* filepath)
{ {
stl_write(filepath, GMIO_STL_FORMAT_BINARY_LE); stl_write(static_cast<const char*>(filepath), GMIO_STL_FORMAT_BINARY_LE);
} }
static void stlb_write_be(const char* filepath) static void stlb_write_be(const void* filepath)
{ {
stl_write(filepath, GMIO_STL_FORMAT_BINARY_BE); stl_write(static_cast<const char*>(filepath), GMIO_STL_FORMAT_BINARY_BE);
} }
} // namespace BmkGmio } // namespace BmkGmio

View File

@ -289,14 +289,14 @@ struct benchmark_cmp_result benchmark_cmp(struct benchmark_cmp_arg arg)
if (arg.func1 != NULL) { if (arg.func1 != NULL) {
struct benchmark_timer timer = {0}; struct benchmark_timer timer = {0};
benchmark_timer_start(&timer); benchmark_timer_start(&timer);
(*arg.func1)(arg.func1_filepath); (*arg.func1)(arg.func1_arg);
result.func1_exec_time_ms = benchmark_timer_elapsed_ms(&timer); result.func1_exec_time_ms = benchmark_timer_elapsed_ms(&timer);
result.has_func1_exec_time = GMIO_TRUE; result.has_func1_exec_time = GMIO_TRUE;
} }
if (arg.func2 != NULL) { if (arg.func2 != NULL) {
struct benchmark_timer timer = {0}; struct benchmark_timer timer = {0};
benchmark_timer_start(&timer); benchmark_timer_start(&timer);
(*arg.func2)(arg.func2_filepath); (*arg.func2)(arg.func2_arg);
result.func2_exec_time_ms = benchmark_timer_elapsed_ms(&timer); result.func2_exec_time_ms = benchmark_timer_elapsed_ms(&timer);
result.has_func2_exec_time = GMIO_TRUE; result.has_func2_exec_time = GMIO_TRUE;
} }

View File

@ -28,7 +28,7 @@ typedef size_t gmio_time_ms_t;
#endif #endif
/*! Typedef on pointer to function to be benchmarked(execution time) */ /*! Typedef on pointer to function to be benchmarked(execution time) */
typedef void (*benchmark_file_func_t)(const char*); typedef void (*benchmark_func_t)(const void*);
/* benchmark_cmp */ /* benchmark_cmp */
@ -38,13 +38,13 @@ struct benchmark_cmp_arg
/*! Brief description of the comparison(eg. "Write to file") */ /*! Brief description of the comparison(eg. "Write to file") */
const char* tag; const char* tag;
/*! Pointer to the 1st function */ /*! Pointer to the 1st function */
benchmark_file_func_t func1; benchmark_func_t func1;
/*! Argument passed to the 1st function on exec */ /*! Argument passed to the 1st function on exec */
const char* func1_filepath; const void* func1_arg;
/*! Pointer to the 2nd function */ /*! Pointer to the 2nd function */
benchmark_file_func_t func2; benchmark_func_t func2;
/*! Argument passed to the 2nd function on exec */ /*! Argument passed to the 2nd function on exec */
const char* func2_filepath; const void* func2_arg;
}; };
/*! Holds the result of the exec time comparison between two functions */ /*! Holds the result of the exec time comparison between two functions */

View File

@ -146,13 +146,13 @@ static float float_strtod(const char* str)
return (float)strtod(str, NULL); return (float)strtod(str, NULL);
} }
static void benchmark_fast_atof(const char* dummy) static void benchmark_fast_atof(const void* dummy)
{ {
GMIO_UNUSED(dummy); GMIO_UNUSED(dummy);
test_internal__run_atof(&fast_atof); test_internal__run_atof(&fast_atof);
} }
static void benchmark_strtod(const char* dummy) static void benchmark_strtod(const void* dummy)
{ {
GMIO_UNUSED(dummy); GMIO_UNUSED(dummy);
test_internal__run_atof(&float_strtod); test_internal__run_atof(&float_strtod);