Show parsing time.
This commit is contained in:
89
test.cc
89
test.cc
@@ -8,6 +8,90 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
#include <windows.h>
|
||||||
|
#include <mmsystem.h>
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#pragma comment(lib, "winmm.lib")
|
||||||
|
#else
|
||||||
|
#if defined(__unix__) || defined(__APPLE__)
|
||||||
|
#include <sys/time.h>
|
||||||
|
#else
|
||||||
|
#include <ctime>
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// not thread-safe
|
||||||
|
class timerutil {
|
||||||
|
public:
|
||||||
|
#ifdef _WIN32
|
||||||
|
typedef DWORD time_t;
|
||||||
|
|
||||||
|
timerutil() { ::timeBeginPeriod(1); }
|
||||||
|
~timerutil() { ::timeEndPeriod(1); }
|
||||||
|
|
||||||
|
void start() { t_[0] = ::timeGetTime(); }
|
||||||
|
void end() { t_[1] = ::timeGetTime(); }
|
||||||
|
|
||||||
|
time_t sec() { return (time_t)((t_[1] - t_[0]) / 1000); }
|
||||||
|
time_t msec() { return (time_t)((t_[1] - t_[0])); }
|
||||||
|
time_t usec() { return (time_t)((t_[1] - t_[0]) * 1000); }
|
||||||
|
time_t current() { return ::timeGetTime(); }
|
||||||
|
|
||||||
|
#else
|
||||||
|
#if defined(__unix__) || defined(__APPLE__)
|
||||||
|
typedef unsigned long int time_t;
|
||||||
|
|
||||||
|
void start() { gettimeofday(tv + 0, &tz); }
|
||||||
|
void end() { gettimeofday(tv + 1, &tz); }
|
||||||
|
|
||||||
|
time_t sec() { return (time_t)(tv[1].tv_sec - tv[0].tv_sec); }
|
||||||
|
time_t msec() {
|
||||||
|
return this->sec() * 1000 +
|
||||||
|
(time_t)((tv[1].tv_usec - tv[0].tv_usec) / 1000);
|
||||||
|
}
|
||||||
|
time_t usec() {
|
||||||
|
return this->sec() * 1000000 + (time_t)(tv[1].tv_usec - tv[0].tv_usec);
|
||||||
|
}
|
||||||
|
time_t current() {
|
||||||
|
struct timeval t;
|
||||||
|
gettimeofday(&t, NULL);
|
||||||
|
return (time_t)(t.tv_sec * 1000 + t.tv_usec);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else // C timer
|
||||||
|
// using namespace std;
|
||||||
|
typedef clock_t time_t;
|
||||||
|
|
||||||
|
void start() { t_[0] = clock(); }
|
||||||
|
void end() { t_[1] = clock(); }
|
||||||
|
|
||||||
|
time_t sec() { return (time_t)((t_[1] - t_[0]) / CLOCKS_PER_SEC); }
|
||||||
|
time_t msec() { return (time_t)((t_[1] - t_[0]) * 1000 / CLOCKS_PER_SEC); }
|
||||||
|
time_t usec() { return (time_t)((t_[1] - t_[0]) * 1000000 / CLOCKS_PER_SEC); }
|
||||||
|
time_t current() { return (time_t)clock(); }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
#ifdef _WIN32
|
||||||
|
DWORD t_[2];
|
||||||
|
#else
|
||||||
|
#if defined(__unix__) || defined(__APPLE__)
|
||||||
|
struct timeval tv[2];
|
||||||
|
struct timezone tz;
|
||||||
|
#else
|
||||||
|
time_t t_[2];
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
static void PrintInfo(const std::vector<tinyobj::shape_t>& shapes, const std::vector<tinyobj::material_t>& materials, bool triangulate = true)
|
static void PrintInfo(const std::vector<tinyobj::shape_t>& shapes, const std::vector<tinyobj::material_t>& materials, bool triangulate = true)
|
||||||
{
|
{
|
||||||
std::cout << "# of shapes : " << shapes.size() << std::endl;
|
std::cout << "# of shapes : " << shapes.size() << std::endl;
|
||||||
@@ -131,8 +215,11 @@ TestLoadObj(
|
|||||||
std::vector<tinyobj::shape_t> shapes;
|
std::vector<tinyobj::shape_t> shapes;
|
||||||
std::vector<tinyobj::material_t> materials;
|
std::vector<tinyobj::material_t> materials;
|
||||||
|
|
||||||
|
timerutil t;
|
||||||
|
t.start();
|
||||||
std::string err;
|
std::string err;
|
||||||
bool ret = tinyobj::LoadObj(shapes, materials, err, filename, basepath, flags);
|
bool ret = tinyobj::LoadObj(shapes, materials, err, filename, basepath, flags);
|
||||||
|
t.end();
|
||||||
|
|
||||||
if (!err.empty()) {
|
if (!err.empty()) {
|
||||||
std::cerr << err << std::endl;
|
std::cerr << err << std::endl;
|
||||||
@@ -143,6 +230,8 @@ TestLoadObj(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("Parse time: %lu [msecs]\n", t.msec());
|
||||||
|
|
||||||
bool triangulate( ( flags & tinyobj::triangulation ) == tinyobj::triangulation );
|
bool triangulate( ( flags & tinyobj::triangulation ) == tinyobj::triangulation );
|
||||||
PrintInfo(shapes, materials, triangulate );
|
PrintInfo(shapes, materials, triangulate );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user