Remove benchmarks source code from repository
It's available in a separated GitHub repository https://github.com/fougue/gmio-benchmarks
This commit is contained in:
parent
4ee7981615
commit
53bd9d08a6
@ -1,131 +0,0 @@
|
||||
#############################################################################
|
||||
## GeomIO Library
|
||||
## Copyright Fougue (2 Mar. 2015)
|
||||
## contact@fougsys.fr
|
||||
##
|
||||
## This software is a reusable library whose purpose is to provide complete
|
||||
## I/O support for various CAD file formats (eg. STL)
|
||||
##
|
||||
## 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".
|
||||
#############################################################################
|
||||
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
|
||||
project(gmio_benchmark)
|
||||
|
||||
#set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||
|
||||
# Options
|
||||
option(BENCHMARK_ASSIMP "Build benchmark for Assimp" ON)
|
||||
option(BENCHMARK_OPENCASCADE "Build benchmark for OpenCascade" ON)
|
||||
|
||||
set(ASSIMP_DIR ${CMAKE_SOURCE_DIR} CACHE PATH "Directory where the Assimp library resides")
|
||||
set(OPENCASCADE_DIR ${CMAKE_SOURCE_DIR} CACHE PATH "Directory where the OpenCascade library resides")
|
||||
set(GMIO_DIR ${CMAKE_SOURCE_DIR} CACHE PATH "Directory where the GeomIO library resides")
|
||||
|
||||
# List source files in commons/
|
||||
file(GLOB COMMONS_FILES commons/*)
|
||||
set(COMMONS_FILES ${COMMONS_FILES})
|
||||
# TODO: check if GMIO_HAVE_STDINT_H is required or not
|
||||
add_definitions(-DGMIO_HAVE_STDINT_H)
|
||||
|
||||
include_directories(${GMIO_DIR}/include)
|
||||
link_directories(${GMIO_DIR}/lib)
|
||||
link_libraries(gmio)
|
||||
if(CMAKE_COMPILER_IS_GNUCC)
|
||||
link_libraries(m) # -lm
|
||||
endif()
|
||||
|
||||
add_executable(bench_gmio bench_gmio/main.c ${COMMONS_FILES})
|
||||
|
||||
function(get_msvc_vernum outVerNum)
|
||||
if(MSVC60)
|
||||
set(${outVerNum} 6 PARENT_SCOPE)
|
||||
elseif(MSVC70)
|
||||
set(${outVerNum} 7 PARENT_SCOPE)
|
||||
elseif(MSVC80)
|
||||
set(${outVerNum} 8 PARENT_SCOPE)
|
||||
elseif(MSVC90)
|
||||
set(${outVerNum} 9 PARENT_SCOPE)
|
||||
elseif(MSVC10)
|
||||
set(${outVerNum} 10 PARENT_SCOPE)
|
||||
elseif(MSVC11)
|
||||
set(${outVerNum} 11 PARENT_SCOPE)
|
||||
elseif(MSVC12)
|
||||
set(${outVerNum} 12 PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
if(BENCHMARK_ASSIMP)
|
||||
add_executable(bench_assimp bench_assimp/main.cpp ${COMMONS_FILES})
|
||||
# Note: we could use target_include_directories() but it's available in cmake > v2.8.10
|
||||
set_property(
|
||||
TARGET bench_assimp
|
||||
APPEND PROPERTY INCLUDE_DIRECTORIES ${ASSIMP_DIR}/include)
|
||||
# Libs
|
||||
find_library(LIBPATH_ASSIMP assimp ${ASSIMP_DIR}/lib64)
|
||||
target_link_libraries(bench_assimp ${LIBPATH_ASSIMP})
|
||||
endif()
|
||||
|
||||
if(BENCHMARK_OPENCASCADE)
|
||||
add_executable(bench_occ
|
||||
bench_occ/main.cpp
|
||||
${GMIO_DIR}/src/gmio_support/stl_occ.cpp
|
||||
${COMMONS_FILES})
|
||||
|
||||
# TODO: define only if target arch is 64b
|
||||
# Noe: we could use target_compile_definitions() but it's available in cmake > v2.8.10
|
||||
set_property(
|
||||
TARGET bench_occ
|
||||
APPEND PROPERTY COMPILE_DEFINITIONS _OCC64)
|
||||
|
||||
if(WIN32)
|
||||
set_property(
|
||||
TARGET bench_occ
|
||||
APPEND PROPERTY COMPILE_DEFINITIONS WNT)
|
||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
set_property(
|
||||
TARGET bench_occ
|
||||
APPEND PROPERTY COMPILE_DEFINITIONS
|
||||
HAVE_CONFIG_H HAVE_FSTREAM HAVE_IOSTREAM HAVE_IOMANIP HAVE_LIMITS_H)
|
||||
endif()
|
||||
|
||||
# Note: we could use target_include_directories() but it's available in cmake > v2.8.10
|
||||
set_property(
|
||||
TARGET bench_occ
|
||||
APPEND PROPERTY INCLUDE_DIRECTORIES ${OPENCASCADE_DIR}/inc)
|
||||
|
||||
# Libs
|
||||
if(MSVC)
|
||||
set(_MSVC_VERNUM_ 0) # Init
|
||||
get_msvc_vernum(_MSVC_VERNUM_)
|
||||
set(OPENCASCADE_LIBDIR ${OPENCASCADE_DIR}/win64/vc${_MSVC_VERNUM_}/lib)
|
||||
elseif((${CMAKE_SYSTEM_NAME} MATCHES "Linux") AND CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(OPENCASCADE_LIBDIR ${OPENCASCADE_DIR}/lin64/gcc/lib)
|
||||
endif()
|
||||
message(STATUS ${OPENCASCADE_LIBDIR})
|
||||
|
||||
find_library(LIBPATH_OPENCASCADE_TKERNEL TKernel ${OPENCASCADE_LIBDIR})
|
||||
find_library(LIBPATH_OPENCASCADE_TKMATH TKMath ${OPENCASCADE_LIBDIR})
|
||||
find_library(LIBPATH_OPENCASCADE_TKSTL TKSTL ${OPENCASCADE_LIBDIR})
|
||||
target_link_libraries(
|
||||
bench_occ
|
||||
${LIBPATH_OPENCASCADE_TKERNEL}
|
||||
${LIBPATH_OPENCASCADE_TKMATH}
|
||||
${LIBPATH_OPENCASCADE_TKSTL})
|
||||
endif()
|
||||
|
||||
|
||||
# Find bit size of the target architecture
|
||||
math(EXPR GMIO_TARGET_ARCH_BIT_SIZE "8 * ${CMAKE_SIZEOF_VOID_P}")
|
||||
|
||||
|
||||
# Specific flags for Visual C++
|
||||
if(MSVC)
|
||||
# Disable deprecation warnings about "non-secure" CRT functions
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
@ -1,353 +0,0 @@
|
||||
#include "../commons/bench_tools.h"
|
||||
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/Exporter.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/cimport.h>
|
||||
|
||||
#include <gmio_core/error.h>
|
||||
#include <gmio_stl/stl_io.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
static unsigned totalTriangleCount(const aiScene* scene)
|
||||
{
|
||||
unsigned int meshnum = 0;
|
||||
for (unsigned int i = 0; i < scene->mNumMeshes; ++i) {
|
||||
for (unsigned int j = 0; j < scene->mMeshes[i]->mNumFaces; ++j)
|
||||
++meshnum;
|
||||
}
|
||||
return meshnum;
|
||||
}
|
||||
|
||||
GMIO_INLINE void copy_gmio_stl_coords(
|
||||
aiVector3D* vec3, const gmio_stl_coords_t& coords)
|
||||
{
|
||||
*vec3 = *((aiVector3D*)&coords);
|
||||
}
|
||||
|
||||
GMIO_INLINE void copy_aiVector3D(
|
||||
gmio_stl_coords_t* coords, const aiVector3D& vec3)
|
||||
{
|
||||
*coords = *((gmio_stl_coords_t*)&vec3);
|
||||
}
|
||||
|
||||
namespace BenchmarkAssimp {
|
||||
|
||||
Assimp::Importer* globalImporter = NULL;
|
||||
const aiScene* globalScene = NULL;
|
||||
|
||||
static void bmk_import(const char* filepath)
|
||||
{
|
||||
Assimp::Importer* importer = globalImporter;
|
||||
const aiScene* scene = importer->ReadFile(filepath, 0);
|
||||
if (aiGetErrorString() != NULL)
|
||||
std::cerr << aiGetErrorString() << 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;
|
||||
}
|
||||
|
||||
static void bmk_export_stla(const char* filepath)
|
||||
{
|
||||
Assimp::Exporter exporter;
|
||||
// for (std::size_t i = 0; i < exporter.GetExportFormatCount(); ++i) {
|
||||
// std::cout << exporter.GetExportFormatDescription(i)->id << " "
|
||||
// << exporter.GetExportFormatDescription(i)->description
|
||||
// << std::endl;
|
||||
// }
|
||||
exporter.Export(globalScene, "stl", filepath);
|
||||
}
|
||||
|
||||
static void bmk_export_stlb(const char* filepath)
|
||||
{
|
||||
Assimp::Exporter exporter;
|
||||
exporter.Export(globalScene, "stlb", filepath);
|
||||
}
|
||||
|
||||
} // namespace BenchAssimp
|
||||
|
||||
static void bench_assimp(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");
|
||||
|
||||
delete BenchmarkAssimp::globalImporter;
|
||||
BenchmarkAssimp::globalImporter = NULL;
|
||||
}
|
||||
|
||||
static void bench_assimp_list(int fileCount, char** files)
|
||||
{
|
||||
for (int i = 0; i < fileCount; ++i)
|
||||
bench_assimp(files[i]);
|
||||
}
|
||||
|
||||
namespace BenchmarkGmio {
|
||||
|
||||
struct aiSceneHelper
|
||||
{
|
||||
aiScene* scene;
|
||||
uint32_t totalTriangleCount;
|
||||
int hasToCountTriangle;
|
||||
};
|
||||
|
||||
aiSceneHelper globalSceneHelper = { 0 };
|
||||
|
||||
static void allocate_stl_scene(aiScene* pScene)
|
||||
{
|
||||
// allocate one mesh
|
||||
pScene->mNumMeshes = 1;
|
||||
pScene->mMeshes = new aiMesh*[1];
|
||||
aiMesh* pMesh = pScene->mMeshes[0] = new aiMesh();
|
||||
pMesh->mMaterialIndex = 0;
|
||||
|
||||
// allocate a single node
|
||||
pScene->mRootNode = new aiNode();
|
||||
pScene->mRootNode->mNumMeshes = 1;
|
||||
pScene->mRootNode->mMeshes = new unsigned int[1];
|
||||
pScene->mRootNode->mMeshes[0] = 0;
|
||||
}
|
||||
|
||||
static void ascii_begin_solid_func(
|
||||
void* cookie, size_t stream_size, const char* solid_name)
|
||||
{
|
||||
aiSceneHelper* helper = (aiSceneHelper*)cookie;
|
||||
helper->hasToCountTriangle = 1; // true
|
||||
aiScene* pScene = helper->scene;
|
||||
allocate_stl_scene(pScene);
|
||||
aiMesh* pMesh = pScene->mMeshes[0];
|
||||
|
||||
std::strcpy(pScene->mRootNode->mName.data, solid_name);
|
||||
pScene->mRootNode->mName.length = std::strlen(solid_name);
|
||||
|
||||
// try to guess how many vertices we could have
|
||||
// assume we'll need 200 bytes for each face
|
||||
const unsigned facetSize = 200u;
|
||||
pMesh->mNumFaces = std::max(1u, static_cast<unsigned>(stream_size) / facetSize);
|
||||
pMesh->mNumVertices = pMesh->mNumFaces * 3;
|
||||
pMesh->mVertices = new aiVector3D[pMesh->mNumVertices];
|
||||
pMesh->mNormals = new aiVector3D[pMesh->mNumVertices];
|
||||
}
|
||||
|
||||
static void binary_begin_solid(
|
||||
void* cookie, uint32_t tri_count, const uint8_t* /*header*/)
|
||||
{
|
||||
aiSceneHelper* helper = (aiSceneHelper*)cookie;
|
||||
helper->hasToCountTriangle = 0; // false
|
||||
aiScene* pScene = helper->scene;
|
||||
allocate_stl_scene(pScene);
|
||||
aiMesh* pMesh = pScene->mMeshes[0];
|
||||
|
||||
pScene->mRootNode->mName.Set("<STL_BINARY>");
|
||||
pMesh->mNumFaces = tri_count;
|
||||
|
||||
pMesh->mNumVertices = pMesh->mNumFaces*3;
|
||||
pMesh->mVertices = new aiVector3D[pMesh->mNumVertices];
|
||||
pMesh->mNormals = new aiVector3D[pMesh->mNumVertices];
|
||||
}
|
||||
|
||||
static void add_triangle(
|
||||
void* cookie, uint32_t tri_id, const gmio_stl_triangle_t* triangle)
|
||||
{
|
||||
aiSceneHelper* helper = (aiSceneHelper*)cookie;
|
||||
aiScene* pScene = helper->scene;
|
||||
aiMesh* pMesh = pScene->mMeshes[0];
|
||||
if (pMesh->mNumFaces <= tri_id) {
|
||||
std::cout << "add_triangle() reallocate" << std::endl;
|
||||
// need to resize the arrays, our size estimate was wrong
|
||||
#if 0
|
||||
unsigned int iNeededSize = (unsigned int)(sz-mBuffer) / pMesh->mNumFaces;
|
||||
if (iNeededSize <= 160)
|
||||
iNeededSize >>= 1; // prevent endless looping
|
||||
unsigned int add = (unsigned int)((mBuffer+fileSize)-sz) / iNeededSize;
|
||||
#endif
|
||||
|
||||
unsigned int add = pMesh->mNumFaces;
|
||||
add += add >> 3; // add 12.5% as buffer
|
||||
const unsigned int iNeededSize = (pMesh->mNumFaces + add)*3;
|
||||
|
||||
aiVector3D* pv = new aiVector3D[iNeededSize];
|
||||
memcpy(pv, pMesh->mVertices, pMesh->mNumVertices*sizeof(aiVector3D));
|
||||
delete[] pMesh->mVertices;
|
||||
pMesh->mVertices = pv;
|
||||
pv = new aiVector3D[iNeededSize];
|
||||
memcpy(pv, pMesh->mNormals, pMesh->mNumVertices*sizeof(aiVector3D));
|
||||
delete[] pMesh->mNormals;
|
||||
pMesh->mNormals = pv;
|
||||
|
||||
pMesh->mNumVertices = iNeededSize;
|
||||
pMesh->mNumFaces += add;
|
||||
}
|
||||
|
||||
aiVector3D* vp = &pMesh->mVertices[tri_id * 3];
|
||||
aiVector3D* vn = &pMesh->mNormals[tri_id * 3];
|
||||
|
||||
copy_gmio_stl_coords(vn, triangle->normal);
|
||||
*(vn+1) = *vn;
|
||||
*(vn+2) = *vn;
|
||||
|
||||
copy_gmio_stl_coords(vp, triangle->v1);
|
||||
copy_gmio_stl_coords(vp+1, triangle->v2);
|
||||
copy_gmio_stl_coords(vp+2, triangle->v3);
|
||||
|
||||
if (helper->hasToCountTriangle)
|
||||
++(helper->totalTriangleCount);
|
||||
}
|
||||
|
||||
static void end_solid(void* cookie)
|
||||
{
|
||||
aiSceneHelper* helper = (aiSceneHelper*)cookie;
|
||||
aiScene* pScene = helper->scene;
|
||||
aiMesh* pMesh = pScene->mMeshes[0];
|
||||
|
||||
if (helper->hasToCountTriangle) {
|
||||
pMesh->mNumFaces = helper->totalTriangleCount;
|
||||
pMesh->mNumVertices = helper->totalTriangleCount * 3;
|
||||
}
|
||||
|
||||
// now copy faces
|
||||
pMesh->mFaces = new aiFace[pMesh->mNumFaces];
|
||||
for (unsigned int i = 0, p = 0; i < pMesh->mNumFaces;++i) {
|
||||
aiFace& face = pMesh->mFaces[i];
|
||||
face.mIndices = new unsigned int[face.mNumIndices = 3];
|
||||
for (unsigned int o = 0; o < 3;++o,++p) {
|
||||
face.mIndices[o] = p;
|
||||
}
|
||||
}
|
||||
|
||||
// create a single default material, using a light gray diffuse color for consistency with
|
||||
// other geometric types (e.g., PLY).
|
||||
aiMaterial* pcMat = new aiMaterial;
|
||||
aiString s;
|
||||
s.Set(AI_DEFAULT_MATERIAL_NAME);
|
||||
pcMat->AddProperty(&s, AI_MATKEY_NAME);
|
||||
|
||||
aiColor4D clrDiffuse(0.6f,0.6f,0.6f,1.0f);
|
||||
pcMat->AddProperty(&clrDiffuse,1,AI_MATKEY_COLOR_DIFFUSE);
|
||||
pcMat->AddProperty(&clrDiffuse,1,AI_MATKEY_COLOR_SPECULAR);
|
||||
clrDiffuse = aiColor4D(0.05f,0.05f,0.05f,1.0f);
|
||||
pcMat->AddProperty(&clrDiffuse,1,AI_MATKEY_COLOR_AMBIENT);
|
||||
|
||||
pScene->mNumMaterials = 1;
|
||||
pScene->mMaterials = new aiMaterial*[1];
|
||||
pScene->mMaterials[0] = pcMat;
|
||||
}
|
||||
|
||||
static void get_triangle(
|
||||
const void* cookie, uint32_t tri_id, gmio_stl_triangle_t* triangle)
|
||||
{
|
||||
const aiMesh* mesh = (const aiMesh*)cookie;
|
||||
const aiFace& f = mesh->mFaces[tri_id];
|
||||
|
||||
// we need per-face normals. We specified aiProcess_GenNormals as
|
||||
// pre-requisite for this exporter, but nonetheless we have to expect
|
||||
// per-vertex normals.
|
||||
aiVector3D nor;
|
||||
if (mesh->mNormals) {
|
||||
for (unsigned int a = 0; a < f.mNumIndices; ++a) {
|
||||
nor += mesh->mNormals[f.mIndices[a]];
|
||||
}
|
||||
nor.Normalize();
|
||||
}
|
||||
copy_aiVector3D(&triangle->normal, nor);
|
||||
#if 0
|
||||
copy_aiVector3D(&triangle->normal, mesh->mNormals[f.mIndices[0]]);
|
||||
#endif
|
||||
|
||||
copy_aiVector3D(&triangle->v1, mesh->mVertices[f.mIndices[0]]);
|
||||
copy_aiVector3D(&triangle->v2, mesh->mVertices[f.mIndices[1]]);
|
||||
copy_aiVector3D(&triangle->v3, mesh->mVertices[f.mIndices[2]]);
|
||||
}
|
||||
|
||||
static void bmk_stl_read(const char* filepath)
|
||||
{
|
||||
gmio_stl_mesh_creator_t mesh_creator = { 0 };
|
||||
mesh_creator.cookie = &globalSceneHelper;
|
||||
mesh_creator.ascii_begin_solid_func = ascii_begin_solid_func;
|
||||
mesh_creator.binary_begin_solid_func = binary_begin_solid;
|
||||
mesh_creator.add_triangle_func = add_triangle;
|
||||
mesh_creator.end_solid_func = end_solid;
|
||||
|
||||
const int error = gmio_stl_read_file(filepath, &mesh_creator, NULL);
|
||||
if (error != GMIO_ERROR_OK)
|
||||
printf("GeomIO error: 0x%X\n", error);
|
||||
|
||||
const aiScene* scene = globalSceneHelper.scene;
|
||||
std::cout << "BenchGmio, triCount = "
|
||||
<< totalTriangleCount(scene) << std::endl;
|
||||
}
|
||||
|
||||
static void bmk_stl_write(const char* filepath, gmio_stl_format_t format)
|
||||
{
|
||||
const aiMesh* sceneMesh = globalSceneHelper.scene->mMeshes[0];
|
||||
|
||||
gmio_stl_mesh_t mesh = { 0 };
|
||||
mesh.cookie = sceneMesh;
|
||||
mesh.triangle_count = sceneMesh->mNumFaces;
|
||||
mesh.get_triangle_func = get_triangle;
|
||||
|
||||
gmio_stl_write_options_t opts = { 0 };
|
||||
opts.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_UPPERCASE;
|
||||
opts.stla_float32_prec = 7;
|
||||
const int error = gmio_stl_write_file(format, filepath, &mesh, NULL, &opts);
|
||||
if (error != GMIO_ERROR_OK)
|
||||
printf("GeomIO error: 0x%X\n", error);
|
||||
}
|
||||
|
||||
static void bmk_stla_write(const char* filepath)
|
||||
{
|
||||
bmk_stl_write(filepath, GMIO_STL_FORMAT_ASCII);
|
||||
}
|
||||
|
||||
static void bmk_stlb_write(const char* filepath)
|
||||
{
|
||||
bmk_stl_write(filepath, GMIO_STL_FORMAT_BINARY_LE);
|
||||
}
|
||||
|
||||
} // namespace BenchmarkGmio
|
||||
|
||||
static void bench_gmio(const char* filepath)
|
||||
{
|
||||
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,
|
||||
"gmio_stl_write(STL_BINARY)",
|
||||
"__file_bench_gmio.stlb");
|
||||
|
||||
delete BenchmarkGmio::globalSceneHelper.scene;
|
||||
BenchmarkGmio::globalSceneHelper.scene = NULL;
|
||||
}
|
||||
|
||||
static void bench_gmio_list(int fileCount, char** files)
|
||||
{
|
||||
for (int i = 0; i < fileCount; ++i)
|
||||
bench_gmio(files[i]);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc > 1) {
|
||||
bench_assimp_list(argc - 1, argv + 1);
|
||||
bench_gmio_list(argc - 1, argv + 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
#include <gmio_core/error.h>
|
||||
#include <gmio_stl/stl_io.h>
|
||||
|
||||
#include "../commons/bench_tools.h"
|
||||
|
||||
typedef struct my_igeom
|
||||
{
|
||||
uint32_t facet_count;
|
||||
} my_igeom_t;
|
||||
|
||||
static void dummy_process_triangle(void* cookie,
|
||||
uint32_t triangle_id,
|
||||
const gmio_stl_triangle_t* triangle)
|
||||
{
|
||||
my_igeom_t* my_igeom = (my_igeom_t*)(cookie);
|
||||
if (my_igeom != NULL)
|
||||
++(my_igeom->facet_count);
|
||||
}
|
||||
|
||||
static void bench_gmio_stl_read(const char* filepath)
|
||||
{
|
||||
my_igeom_t cookie = { 0 };
|
||||
gmio_stl_mesh_creator_t mesh_creator = { 0 };
|
||||
int error = GMIO_ERROR_OK;
|
||||
|
||||
mesh_creator.cookie = &cookie;
|
||||
mesh_creator.add_triangle_func = dummy_process_triangle;
|
||||
error = gmio_stl_read_file(filepath, &mesh_creator, NULL);
|
||||
if (error != GMIO_ERROR_OK)
|
||||
printf("GeomIO error: 0x%X\n", error);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc > 1) {
|
||||
benchmark_list(&bench_gmio_stl_read,
|
||||
"gmio_stl_read_file()",
|
||||
argc - 1, argv + 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
#include <OSD_Path.hxx>
|
||||
#include <RWStl.hxx>
|
||||
#include <StlMesh_Mesh.hxx>
|
||||
|
||||
#include <gmio_core/error.h>
|
||||
#include <gmio_stl/stl_io.h>
|
||||
#include <gmio_support/stl_occ.h>
|
||||
|
||||
#include "../commons/bench_tools.h"
|
||||
|
||||
static void bench_occ_RWStl_ReadFile(const char* filepath)
|
||||
{
|
||||
RWStl::ReadFile(OSD_Path(filepath));
|
||||
}
|
||||
|
||||
static void bench_gmio_stl_read(const char* filepath)
|
||||
{
|
||||
Handle_StlMesh_Mesh mesh = new StlMesh_Mesh;
|
||||
gmio_stl_mesh_creator_t mesh_creator = gmio_stl_occmesh_creator(mesh);
|
||||
int error = gmio_stl_read_file(filepath, &mesh_creator, NULL);
|
||||
if (error != GMIO_ERROR_OK)
|
||||
printf("GeomIO error: 0x%X\n", error);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc > 1) {
|
||||
benchmark_list(&bench_occ_RWStl_ReadFile,
|
||||
"RWStl::ReadFile()",
|
||||
argc - 1, argv + 1);
|
||||
|
||||
benchmark_list(&bench_gmio_stl_read,
|
||||
"gmio_stl_read()",
|
||||
argc - 1, argv + 1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
#include "bench_tools.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
float elapsed_secs(clock_t start_tick)
|
||||
{
|
||||
return (float)((clock() - start_tick) / (float)CLOCKS_PER_SEC);
|
||||
}
|
||||
|
||||
void benchmark_list(bench_file_func_t func, const char* title, int argc, char **argv)
|
||||
{
|
||||
const clock_t start_tick = clock();
|
||||
int iarg;
|
||||
|
||||
if (func == NULL)
|
||||
return;
|
||||
|
||||
printf("Bench %s ...\n", title);
|
||||
for (iarg = 0; iarg < argc; ++iarg) {
|
||||
printf(" File %s ...\n", argv[iarg]);
|
||||
(*func)(argv[iarg]);
|
||||
}
|
||||
printf(" exec time: %.2fs\n\n", elapsed_secs(start_tick));
|
||||
}
|
||||
|
||||
void benchmark(bench_file_func_t func, const char *title, const char* filepath)
|
||||
{
|
||||
benchmark_list(func, title, 1, (char**)&filepath);
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
#ifndef BENCH_TOOLS_H
|
||||
#define BENCH_TOOLS_H
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include <gmio_core/global.h>
|
||||
|
||||
GMIO_C_LINKAGE_BEGIN
|
||||
|
||||
float elapsed_secs(clock_t start_tick);
|
||||
|
||||
typedef void (*bench_file_func_t)(const char*);
|
||||
|
||||
void benchmark_list(
|
||||
bench_file_func_t func, const char* title, int argc, char** argv);
|
||||
|
||||
void benchmark(
|
||||
bench_file_func_t func, const char* title, const char* filepath);
|
||||
|
||||
GMIO_C_LINKAGE_END
|
||||
|
||||
#endif /* BENCH_TOOLS_H */
|
Loading…
Reference in New Issue
Block a user