it's 2:50 AM here and after a hectic day I found something strange. I do my best to give a picture of my problem.
I wrote these two pieces of code in C++
and JavaScript
:
#include<stdio.h>
#include <time.h>
int main() {
clock_t tStart = clock();
int result = 0;
for (int a = 0; a < 1000000000;a++) {
result += a;
}
printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
return 1;
}
And:
var start = new Date().getTime();
var result = 0;
for(var a = 0;a < 1000000000;a++) {
result += a;
}
var end = new Date().getTime();
var time = end - start;
console.log('Time taken: ' + (time/1000) + 's');
Both of them do the same thing (I hope so)
After generating ./a.out.js
using the latest version of emscripten, I found something weird:
The execution time of the emscripten code is really slower than the manually written JavaScript code. What's the problem?
node.js lacks most of the real asm.js performance tweaks that make emscripten fast. Instead of trying it with node, try it in firefox or chrome.
The issue is that node.js tends to lag behind chrome's V8 version, so features (or optimizations) that go into Chrome may take quite awhile to make it into V8. I don't actually know how long, but the asm.js optimizations are new enough that when I last tried it in early April, 2014 it was significantly slower on the command line with node.js than in the browser with Chrome, and Firefox was faster still.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With