Closed MichaReiser closed 7 years ago
Not yet. I am planning to do some encoding/ decoding benchmark.
I also prepared n-body bench, but I'm waiting wasm's sqrt op.
@max then I will try to add sqrt support today :)
@nidin check slack plz. I have some questions.
MaxGraey's N-Body Benchmark results WebAssembly vs JavaScript
It's without binaryen optimizations?
Yes. I tried binaryen but was getting errors. I don't know what is the problem.
It seems a good result as for unoptimized version! I think next we should add same bench test for c++ (emscripten).
Thank you. That's what I expected :( JavaScript is faster than most of us think it is. Furthermore, I believe that the JITs have still some room concerning optimizing WASM.
To be honest. I'm a little bit released to see these results. This would have been trouble to my master thesis if your code would have been significantly faster than JS ;)
It seems a good result as for unoptimized version! I think next we should add same bench test for c++ (emscripten).
That's a good idea. Just ensure that you use at least -O2
@MichaReiser can you add n-body test to your bench tests? You can find sources here. It will be interesting how LLVM optimize this bench.
@MaxGraey I just wanted to ask you if you can give me the JS source. So, thanks! Will take a look soon.
hmm... If i look at the result... WASM and JS do not return the same results
Chrome JS: 1.54775s 🎉 WASM: 1.91057s
Firefox: JS: 1.360125s 🎉 WASM: 1.3785s
I prefer the results of Firefox. In my case, both implementations return the same result.
A side note. WebAssembly is also about predictability concerning performance. And this is true in this case. The variance of the WASM implementation is lower than the one of the JS implementation (at least using chrome. This is not the case for FF)
js x 0.64 ops/sec ±1.52% (8 runs sampled) wasm x 0.51 ops/sec ±0.97% (7 runs sampled)
MacBook Mid 2014
Good numbers.
Where is the benchmark code, I'll create a C/C++ version if I have time today?
This http://benchmarksgame.alioth.debian.org/u64q/program.php?test=nbody&lang=typescript&id=3 from The Computer Language Benchmark Game http://benchmarksgame.alioth.debian.org/ looks similar, but not exactly.
Where did you get yours? I'm guessing wherever that was there is already a C version, like this one http://benchmarksgame.alioth.debian.org/u64q/program.php?test=nbody&lang=gcc&id=4 from The Computer Language Benchmark Game.
On Thu, May 25, 2017 at 9:03 AM Max Graey notifications@github.com wrote:
@winksaville https://github.com/winksaville code https://github.com/MaxGraey/TurboScript/blob/MaxGraey/add-benchmark/benchmark/n-body/ts/index.ts
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/01alchemist/TurboScript/issues/77#issuecomment-304049095, or mute the thread https://github.com/notifications/unsubscribe-auth/AA-hHBvkph5w3Rq8qbeW1LDeB-gVtu9pks5r9aZUgaJpZM4NV0E- .
I ran the same benchmark with optimizations disabled:
Chrome js: 1.63425s wasm: 3.4968s
Firefox js: 1.463375s wasm: 3.14s
So, the optimization make a huge difference!
Something I want to add. I believe nbody is not a good benchmark to show that TurboScript can be faster. The problem here is, that nbody makes no use of CPU instructions that only WASM offers. Furthermore, a JIT compiler can generate at least as efficient native code for this implementation as any offline compiler.
I suspect the reason is that it's early days for the internal wasm compilers, but time will tell. Sorry about my previous post, I did it using the google inbox "link" command which obviously doesn't translate well to github markup :(
On Thu, May 25, 2017 at 9:31 AM Micha Reiser notifications@github.com wrote:
I ran the same benchmark with optimizations disabled:
Chrome js: 1.63425s wasm: 3.4968s
Firefox js: 1.463375s wasm: 3.14s
So, the optimization make a huge difference!
Something I want to add. I believe nbody is not a good benchmark to show that TurboScript can be faster. The problem here is, that nbody makes no use of CPU instructions that only WASM offers. Furthermore, a JIT compiler can generate at least as efficient native code for this implementation as any offline compiler.
- There are no dynamic JS features. So, the optimizer can do a good job
- JIT optimizer have more information at hand. E.g. is a function only called with a specific value and, therefore, can some checks be removed
- A jit optimizer can perform more aggressive inlining as the code overhead has no affect on the compiled file (it's just in the memory).
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/01alchemist/TurboScript/issues/77#issuecomment-304056245, or mute the thread https://github.com/notifications/unsubscribe-auth/AA-hHBuBYDEZa2yGUzx7cM7k2mHaqRb_ks5r9azbgaJpZM4NV0E- .
@MichaReiser LLVM do the same job: aggressive inlining, dead code illumination, precompute constant expressions and much more and I think it should do this better then JIT which need balance between quality of optimization and time of compilation in memory.
n-body bench is very common test for any language. I think computing fib
or isPrime
is more syntactic
@MichaReiser LLVM do the same job: aggressive inlining, dead code illumination, precompute constant expressions and much more and I think it should do this better then JIT which need balance between quality of optimization and time of compilation in memory.
The point about balancing is true. However, if you look at a function that is generally only called with non null values. However, it also accepts null values. An offline compiler cannot remove those branches (except the function is inlined) as there might be the case where the function is actually called with null. A JIT compiler, on the contrary, can remove all branches for null if the function has never been called with null (if the function is called once with a null value, a deopt is needed). So there are cases where JIT compilers can achieve better results.
Yes, n-body is a common benchmark. But I just do not expect any benefits over plain JavaScript. It does not use any features that wasm supports better than JS
Just a short update
I implemented the nbody benchmark using emscripten:
Chrome:
nbody...
js x 0.65 ops/sec ±1.19% (8 runs sampled)
emcc x 0.62 ops/sec ±0.54% (8 runs sampled)
wasm x 0.49 ops/sec ±0.57% (7 runs sampled)
Firefox:
nbody...
js x 0.76 ops/sec ±1.81% (8 runs sampled)
emcc x 0.81 ops/sec ±0.92% (8 runs sampled)
wasm x 0.70 ops/sec ±1.05% (8 runs sampled)
I need to investigate what causes the difference between Emscripten and my implementation. But it should be possible to be, at least, as fast as JavaScript.
The source code of the C++ implementation is located here (I also inlined most of the variables in the JavaScript implementations).
I'm just curious. Do you have any benchmark that compares TurboScript with JS or Emscripten?