-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Can I get high precision timing with EMSDK 4.0.5? #24267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We don't any anything in emscripten to alter the precision provided by node. The
As far as I know this has not changed since 3.1.22 so I would not expect to see a difference in the precision. How are you measuring this? I certainly see sub-millisecond precision under node:
|
(FYI, |
Thanks for your reply @sbc100 This is my code:
I want to determine the processing time for some work, so I declared t1 as the start time and t2 as the end time. Here are the logs — the values after the decimal point are always zero.
And here is the compiler flags set set(WASM_AEC_FLAGS -O3 -g0 -s MODULARIZE=1 -s DYNAMIC_EXECUTION=0 -s EXPORT_NAME="createModule" -s EXPORTED_FUNCTIONS=['_malloc','_free'] -s INITIAL_MEMORY=18MB -s BINARYEN_ASYNC_COMPILATION=0 -s ENVIRONMENT=node) Thanks. |
I checked the generated JS, and noticed the same code with yours I can get correct float values with the same C++ code with 3.1.22 and Node16
|
The fact that you are seeing no decimal places is very odd. If you simply run
Something strange must be going on with how the result of How are you printing the values? Can you run the above tiny program to confirm that you see the same types of values that I do? |
I've tested node18, node20 and node22 with the tiny program. All of them work fine. |
Could you share the full set of link flag you use in your larger program. Also are you actually using printf, or something else to print the time? |
I have a performance polyfill like below:
In Node.js 16, the performance object was automatically exposed in the module scope. So performance is defined and Date.now() will not executed and emscripten_get_now() returns a float value with high precision. However, Node.js 20 enforces stricter module encapsulation. With the above code, performance is not defined and Date.now() will be executed and emscripten_get_now() returns low precision value. After I use if (typeof globalThis.performance === 'undefined') to check if performance is defined, the issue has been resolved. Thank you very much @sbc100 |
Hello, I'm testing some C++ code compiled with EMSDK 4.0.5 in NodeJS 20.
I'd like to achieve timing under 1ms, but encountering issues here
I've tried various methods to obtain high precision timing, including using emscripten_get_now and std::chrono::high_resolution_clock::now(), but none have provided precision below 1ms.
I also tried adding compiling flags like -s ENVIRONMENT=node -s PRECISE_F32=1, but they didn't work either.
I understand that there are some security reasons for this, but I'm just wondering if there is a way to overcome this issue?
There was no such issue with emsdk 3.1.22, I upgraded the emsdk recently and noticed this problem.
Thanks.
The text was updated successfully, but these errors were encountered: