@@ -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
3034using namespace std ;
@@ -53,6 +57,10 @@ result_t measure(clock_t *times) {
5357}
5458
5559int 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