Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fe7fd75

Browse filesBrowse files
committed
improve box2d benchmarking
1 parent 2877208 commit fe7fd75
Copy full SHA for fe7fd75

1 file changed

+18-3Lines changed: 18 additions & 3 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎tests/box2d/Benchmark.cpp‎

Copy file name to clipboardExpand all lines: tests/box2d/Benchmark.cpp
+18-3Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ typedef struct {
2525
#include <time.h>
2626
#include <math.h>
2727

28+
#if EMSCRIPTEN
29+
#include <emscripten.h>
30+
#endif
31+
2832
#include "Box2D/Box2D.h"
2933

3034
using namespace std;
@@ -53,6 +57,10 @@ result_t measure(clock_t *times) {
5357
}
5458

5559
int main(int argc, char **argv) {
60+
#if EMSCRIPTEN
61+
emscripten_run_script("if (Module.reportStartedUp) Module.reportStartedUp()");
62+
#endif
63+
5664
int arg = argc > 1 ? argv[1][0] - '0' : 3;
5765
switch(arg) {
5866
case 0: return 0; break;
@@ -64,6 +72,10 @@ int main(int argc, char **argv) {
6472
default: printf("error: %d\\n", arg); return -1;
6573
}
6674

75+
// do not split out warmup, do not ignore initial stalls
76+
FRAMES += WARMUP;
77+
WARMUP = 0;
78+
6779
// Define the gravity vector.
6880
b2Vec2 gravity(0.0f, -10.0f);
6981

@@ -115,12 +127,15 @@ int main(int argc, char **argv) {
115127
world.Step(1.0f/60.0f, 3, 3);
116128
}
117129

118-
clock_t times[FRAMES];
130+
clock_t times[FRAMES], min = CLOCKS_PER_SEC * 1000 * 100, max = -1;
119131
for (int32 i = 0; i < FRAMES; ++i) {
120132
clock_t start = clock();
121133
world.Step(1.0f/60.0f, 3, 3);
122134
clock_t end = clock();
123-
times[i] = end - start;
135+
clock_t curr = end - start;
136+
times[i] = curr;
137+
if (curr < min) min = curr;
138+
if (curr > max) max = curr;
124139
#if DEBUG
125140
printf("%f :: ", topBody->GetPosition().y);
126141
printf("%f\n", (float32)(end - start) / CLOCKS_PER_SEC * 1000);
@@ -129,7 +144,7 @@ int main(int argc, char **argv) {
129144

130145
result_t result = measure(times);
131146

132-
printf("frame averages: %.3f +- %.3f\n", result.mean, result.stddev);
147+
printf("frame averages: %.3f +- %.3f, range: %.3f to %.3f \n", result.mean, result.stddev, float(min)/CLOCKS_PER_SEC * 1000, float(max)/CLOCKS_PER_SEC * 1000);
133148

134149
return 0;
135150
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.