2
#include "emscripten.h"
5
// To be able to run this test outside the browser harness in node.js/spidermonkey:
6
#define REPORT_RESULT int dummy
12
// This code tests three things:
13
// a) Calling emscripten_get_now(), time actually proceeds.
14
// b) Values returned by emscripten_get_now() are strictly nondecreasing.
15
// c) emscripten_get_now() is able to return sub-millisecond precision timer values.
16
bool detected_good_timer_precision = false;
17
float smallest_delta = 0.f;
18
for(int x = 0; x < 1000; ++x) { // Have several attempts to find a good small delta, i.e. give time to JS engine to warm up the code and so on.
19
float t = emscripten_get_now();
20
float t2 = emscripten_get_now();
21
for(int i = 0; i < 100 && t == t2; ++i) {
22
t2 = emscripten_get_now();
25
if (t2 < t && t2 - t < 1000.f) { // Timer must be monotonous.
26
printf("Timer is not monotonous!\\n");
27
smallest_delta = t2 - t;
30
if (t2 > t && t2 - t < 0.7f) { // Must pass less than a millisecond between two calls.
31
detected_good_timer_precision = true;
32
smallest_delta = t2 - t;
37
if (detected_good_timer_precision) {
38
printf("Timer resolution is good. (%f msecs)\\n", smallest_delta);
41
printf("Error: Bad timer precision: Smallest timer delta: %f msecs\\n", smallest_delta);