4 ms·
Exciting... trying it as I type! Edit: I'm trying to run the following benchmarks [1]: function mySlowFunction(baseNumber) { console.time('mySlowFunc
by syrusakbary 5y ago
Exciting... trying it as I type!
Edit: I'm trying to run the following benchmarks [1]:
function mySlowFunction(baseNumber) {
console.time('mySlowFunction');
let result = 0;
for (var i = Math.pow(baseNumber, 7); i >= 0; i--) {
result += Math.atan(i) * Math.tan(i);
};
console.timeEnd('mySlowFunction');
}
mySlowFunction(8); // higher number => more iterations => slower
Results: 99ms in my Chromium browser (v8 JIT enabled), it breaks in the WebVM (after typing `node` and enter) with `TODO: FAULT af5147bf / CODE da d9 83`
Results (not using console time): 99ms in my Chromium browser (v8 JIT enabled), 680ms in WebVM (1050ms in the first run).
Conclusion: WebVM node is only 7 times slower than native v8 in my local machine (macOS M1 Max)
[1]: https://gist.github.com/sqren/5083d73f184acae0c5b7 https://gist.github.com/sqren/5083d73f184acae0c5b7
- apignotti 5y agoThat's an unimplemented instruction. If I have to make a guess, one the trigonometric funcs you are calling. Feel free to report a bug if you'd like.
- Recursing 5y agoThe issue is triggered by `console.time` Try: function mySlowFunction(baseNumber) { const startTime = Date.now(); let result = 0; for (var i = Math.pow(baseNumber, 7); i >= 0; i--) { result += Math.atan(i) * Math.tan(i); }; console.log(result, 'time:', Date.now() - startTime); } mySlowFunction(8); I get ~100ms in Chromium and ~900ms in the WebVM (if I close the devtools)
- marwis 5y agoIf you want Node in your browser, stackblitz has a super fast implementation. I think it's NodeJS compiled to Wasm but with V8 replaced by browser's native JS engine: https://blog.stackblitz.com/posts/introducing-webcontainers/ https://blog.stackblitz.com/posts/introducing-webcontainers/