Closed juj closed 12 years ago
Firefox and Chrome dev versions have window.performance.now() which is high-resolution. There seems to be no libc or SDL API that is suitable to expose it, so I guess we need to provide our own.
Implemented in incoming as emscripten_get_now
.
Many thanks!
The commit https://github.com/kripken/emscripten/commit/354a88d763284fae92a59d311f8562542ad10a97 also cleared up for me how to go implementing my own new functions, so that I can start hacking on the API :)
Merged to master.
Get hacking! :)
I did some tests with different ways to compute the time:
I could not find CLOCK_PROCESS_CPUTIME_ID or CLOCK_THREAD_CPUTIME_ID to be defined, so they were omitted from the test. The resulting application is live at http://dl.dropbox.com/u/40949268/emcc/Geometry_time.html
The results:
The best way so far is to use clock() to get at least millisecond precision. What is the status of doing high-performance timers on web? Googling a bit:
There's at least this: http://www.w3.org/TR/hr-time/
But I suppose the reality today looks like this? http://stackoverflow.com/questions/6875625/does-javascript-provide-a-high-resolution-timer
Perhaps making two functions to enable code to adapt to different granularities: emscripten_clock_tick() returns a current wallclock time in best available timer in the browser, and emscripten_clock_ticks_per_sec() which would return the frequency that timer is running at? Alternatively (additionally?), just make use of clock_gettime(CLOCK_REALTIME) directly, instead of returning 0?
I would be happy to get access to a high-precision timer. That would allow me to bring my code performance profiler over ( http://dl.dropbox.com/u/40949268/Asteroids/Asteroids-Tegra3.png ) to measure the performance in the browser.