-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.cpp
More file actions
70 lines (54 loc) · 1.85 KB
/
benchmark.cpp
File metadata and controls
70 lines (54 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "rapidobj.hpp"
#include <algorithm>
#include <chrono>
#include <iostream>
#include <numeric>
#include <vector>
int main(int argc, char **argv) {
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " <obj_path> [iterations]\n";
return 1;
}
const char *obj_path = argv[1];
int iterations = argc > 2 ? std::stoi(argv[2]) : 5;
std::cout << "Parsing: " << obj_path << "\n";
std::cout << "Iterations: " << iterations << "\n";
std::cout << "--------------------------------------------------\n";
std::vector<double> times;
rapidobj::Result result;
for (int i = 0; i < iterations; ++i) {
auto start = std::chrono::high_resolution_clock::now();
result = rapidobj::ParseFile(obj_path);
if (result.error) {
std::cerr << "Error: " << result.error.code.message() << "\n";
return 1;
}
rapidobj::Triangulate(result);
auto end = std::chrono::high_resolution_clock::now();
auto elapsed =
std::chrono::duration<double, std::milli>(end - start).count();
times.push_back(elapsed);
}
std::cout << "Parse times: [";
for (size_t i = 0; i < times.size(); ++i) {
if (i > 0)
std::cout << ", ";
std::cout << times[i];
}
std::cout << "] ms\n";
double avg = std::accumulate(times.begin(), times.end(), 0.0) / times.size();
double min_t = *std::min_element(times.begin(), times.end());
double max_t = *std::max_element(times.begin(), times.end());
std::cout << "Average: " << avg << " ms\n";
std::cout << "Min: " << min_t << " ms\n";
std::cout << "Max: " << max_t << " ms\n";
// Count faces
size_t face_count = 0;
for (const auto &shape : result.shapes) {
face_count += shape.mesh.indices.size() / 3;
}
std::cout << "\nVertices: (" << result.attributes.positions.size() / 3
<< ", 3)\n";
std::cout << "Faces: (" << face_count << ", 3)\n";
return 0;
}