|
11 | 11 | #include <sstream> |
12 | 12 | #include <fstream> |
13 | 13 |
|
| 14 | +#ifdef _WIN32 |
| 15 | +#ifdef __cplusplus |
| 16 | +extern "C" { |
| 17 | +#endif |
| 18 | +#include <windows.h> |
| 19 | +#include <mmsystem.h> |
| 20 | +#ifdef __cplusplus |
| 21 | +} |
| 22 | +#endif |
| 23 | +#pragma comment(lib, "winmm.lib") |
| 24 | +#else |
| 25 | +#if defined(__unix__) || defined(__APPLE__) |
| 26 | +#include <sys/time.h> |
| 27 | +#else |
| 28 | +#include <ctime> |
| 29 | +#endif |
| 30 | +#endif |
| 31 | + |
| 32 | +class timerutil { |
| 33 | +public: |
| 34 | +#ifdef _WIN32 |
| 35 | + typedef DWORD time_t; |
| 36 | + |
| 37 | + timerutil() { ::timeBeginPeriod(1); } |
| 38 | + ~timerutil() { ::timeEndPeriod(1); } |
| 39 | + |
| 40 | + void start() { t_[0] = ::timeGetTime(); } |
| 41 | + void end() { t_[1] = ::timeGetTime(); } |
| 42 | + |
| 43 | + time_t sec() { return (time_t)((t_[1] - t_[0]) / 1000); } |
| 44 | + time_t msec() { return (time_t)((t_[1] - t_[0])); } |
| 45 | + time_t usec() { return (time_t)((t_[1] - t_[0]) * 1000); } |
| 46 | + time_t current() { return ::timeGetTime(); } |
| 47 | + |
| 48 | +#else |
| 49 | +#if defined(__unix__) || defined(__APPLE__) |
| 50 | + typedef unsigned long int time_t; |
| 51 | + |
| 52 | + void start() { gettimeofday(tv + 0, &tz); } |
| 53 | + void end() { gettimeofday(tv + 1, &tz); } |
| 54 | + |
| 55 | + time_t sec() { return static_cast<time_t>(tv[1].tv_sec - tv[0].tv_sec); } |
| 56 | + time_t msec() { |
| 57 | + return this->sec() * 1000 + |
| 58 | + static_cast<time_t>((tv[1].tv_usec - tv[0].tv_usec) / 1000); |
| 59 | + } |
| 60 | + time_t usec() { |
| 61 | + return this->sec() * 1000000 + static_cast<time_t>(tv[1].tv_usec - tv[0].tv_usec); |
| 62 | + } |
| 63 | + time_t current() { |
| 64 | + struct timeval t; |
| 65 | + gettimeofday(&t, NULL); |
| 66 | + return static_cast<time_t>(t.tv_sec * 1000 + t.tv_usec); |
| 67 | + } |
| 68 | + |
| 69 | +#else // C timer |
| 70 | + // using namespace std; |
| 71 | + typedef clock_t time_t; |
| 72 | + |
| 73 | + void start() { t_[0] = clock(); } |
| 74 | + void end() { t_[1] = clock(); } |
| 75 | + |
| 76 | + time_t sec() { return (time_t)((t_[1] - t_[0]) / CLOCKS_PER_SEC); } |
| 77 | + time_t msec() { return (time_t)((t_[1] - t_[0]) * 1000 / CLOCKS_PER_SEC); } |
| 78 | + time_t usec() { return (time_t)((t_[1] - t_[0]) * 1000000 / CLOCKS_PER_SEC); } |
| 79 | + time_t current() { return (time_t)clock(); } |
| 80 | + |
| 81 | +#endif |
| 82 | +#endif |
| 83 | + |
| 84 | +private: |
| 85 | +#ifdef _WIN32 |
| 86 | + DWORD t_[2]; |
| 87 | +#else |
| 88 | +#if defined(__unix__) || defined(__APPLE__) |
| 89 | + struct timeval tv[2]; |
| 90 | + struct timezone tz; |
| 91 | +#else |
| 92 | + time_t t_[2]; |
| 93 | +#endif |
| 94 | +#endif |
| 95 | +}; |
| 96 | + |
14 | 97 | static void PrintInfo(const tinyobj::attrib_t &attrib, const std::vector<tinyobj::shape_t>& shapes, const std::vector<tinyobj::material_t>& materials) |
15 | 98 | { |
16 | 99 | std::cout << "# of vertices : " << (attrib.vertices.size() / 3) << std::endl; |
@@ -55,7 +138,7 @@ static void PrintInfo(const tinyobj::attrib_t &attrib, const std::vector<tinyobj |
55 | 138 | for (size_t f = 0; f < shapes[i].mesh.num_face_vertices.size(); f++) { |
56 | 139 | size_t fnum = shapes[i].mesh.num_face_vertices[f]; |
57 | 140 |
|
58 | | - printf(" face[%ld].fnum = %d\n", static_cast<long>(f), static_cast<unsigned long>(fnum)); |
| 141 | + printf(" face[%ld].fnum = %ld\n", static_cast<long>(f), static_cast<unsigned long>(fnum)); |
59 | 142 |
|
60 | 143 | // For each vertex in the face |
61 | 144 | for (size_t v = 0; v < fnum; v++) { |
@@ -147,8 +230,12 @@ TestLoadObj( |
147 | 230 | std::vector<tinyobj::shape_t> shapes; |
148 | 231 | std::vector<tinyobj::material_t> materials; |
149 | 232 |
|
| 233 | + timerutil t; |
| 234 | + t.start(); |
150 | 235 | std::string err; |
151 | 236 | bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, filename, basepath, triangulate); |
| 237 | + t.end(); |
| 238 | + printf("Parsing time: %lu [msecs]\n", t.msec()); |
152 | 239 |
|
153 | 240 | if (!err.empty()) { |
154 | 241 | std::cerr << err << std::endl; |
|
0 commit comments