-
Notifications
You must be signed in to change notification settings - Fork 122
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
bug: the walt file of wasm spended more time than js #184
Comments
If you think that WebAssembly is always faster than pure JS, you are wrong. Perhaps, it may be faster if you compile a complex program which uses a decent amount of RAM into WA completely. But if it's about simple algorithm you will not get much benefit. I say it all out of my own experience, which is based on some experiments 2-3 years ago. Maybe now or in the future it will change, but the fact is that JS is very well optimized, but calls to WA functions probably have some overhead, so in case of simple fast functions, there is no benefit from WA. |
thank you for your answer,let me make the wasm more understand!
陈标发
邮箱:[email protected]
签名由 网易邮箱大师 定制
On 09/26/2020 23:41, RussCoder wrote:
If you think that WebAssembly is always faster than pure JS, you are wrong.
I also used to think so, but after experimenting with it, I found out that it's either works with the same speed or slower than JS. The key reason is that JS is rather well optimized and JIT-compiled, so in case of very simple functions like yours, it will be not-slower than WA (or even faster as you write).
Perhaps, it may be faster if you compile a complex program which uses a decent amount of RAM into WA completely. But if it's about simple algorithm you will not get much benefit.
I say it all out of my own experience, which is based on some experiments 2-3 years ago. Maybe now or in the future it will change, but the fact is that JS is very well optimized, but calls to WA functions probably have some overhead, so in case of simple fast functions, there is no benefit from WA.
—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or unsubscribe.
[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "#184 (comment)",
"url": "#184 (comment)",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]
|
@CBulFel it really depends on compiler and browser. For example AssemblyScript (wasm) on latest Chrome perform this test 3x faster than JS. See benchmark fiddle: https://webassembly.studio/?f=rx60wjdye9h PS export function sum(n: i32): i32 {
if (n < 1) return 0;
return i32(u64(n - 1) * u64(n - 2) / 2) + (n - 1);
} and perform instantly with O(1) time |
`
walt:
export function SUM(n: i32): i32 {
}
SUMWalt().then(wasmModule => {
const begin = Date.now()
console.log('wasm begin: ', begin)
console.log('wasm:', wasmModule.instance.exports.SUM(999999999)) // 1
console.log('wasm end: ', Date.now() - begin)
})
js:
function SUM(n) {
}
const begin = Date.now()
console.log('js begin: ', begin)
console.log('js: ', SUM(999999999)) // 1
console.log('js end: ', Date.now() - begin)
`
result:
the SUM funtion return value is not the same, and the wasm time more than js time.
The text was updated successfully, but these errors were encountered: