That is a small benchmark to check how efficient each language can call JS functions, from their host language.
The set of tests was designed to see the performance overhead, and not the performance of the given language on WASM.
- Golang:
/go: UsesCallImportmagic instruction and usesmain_raw_js.jsas binding tooom.js./go-syscall: Usessyscall/jspackage to calloom.jswithout any optimization./go-syscall-invoke: Usessyscall/jspackage to calloom.jswith some optimization (using.Invokeinstead of new.Call).
- Zig:
/zig: Usesextern fnto call imports and useswasm.jsas binding tooom.js.
- Rust:
/rust: Usesexternto call imports andwasm_bindgento create the bindings tooom.js.
- C#:
/csharp: UsesJsRuntimeto calloom.jspackage without any optimization.
The host-language must send one string containing all characters as "A". Each iteration of the loop must increase the
size of the string by one. The JS must receive it as String, using TextDecoder or equivalent, facing the performance
penalty.
The host-language must create and send one disposable byte-array containing all bytes as 0x00. The size of the
byte-array must be the index of the current iteration. The JS must receive it as Uint8Array.
The host-language must call it, without provide any argument.
| TestString-20000 | TestBytes-20000 | TestVoid-20000 | |
|---|---|---|---|
| Zig | ~39ms | ~71ms | ~1ms |
| Rust | ~40ms | ~73ms | ~1ms |
| Golang | ~42ms | ~124ms | ~1ms |
| Golang-Invoke | ~311ms | ~227ms | ~9ms |
| Golang-Syscall | ~335ms | ~321ms | ~21ms |
| C# | ~2449ms | ~815ms | ~510ms |
| TestString-20000 | TestBytes-20000 | TestVoid-20000 | |
|---|---|---|---|
| Zig | ~253ms | ~51ms | ~0ms |
| Rust | ~247ms | ~121ms | ~0ms |
| Golang | ~252ms | ~86ms | ~0ms |
| Golang-Invoke | ~217ms | ~324ms | ~4ms |
| Golang-Syscall | ~251ms | ~509ms | ~22ms |
| C# | ~3136ms | ~1684ms | ~810ms |
| TestString-10000 | TestBytes-10000 | TestVoid-10000 | |
|---|---|---|---|
| Zig | ~223ms | ~56ms | ~0ms |
| Rust | ~212ms | ~135ms | ~0ms |
| Golang | ~230ms | ~198ms | ~1ms |
| Golang-Invoke | ~338ms | ~625ms | ~6ms |
| Golang-Syscall | ~397ms | ~984ms | ~84ms |
| C# | CRASH | CRASH | CRASH |
See /release.sh file to see how the /_html was created and how it compiles each language.
You can try it online. If you want to run it locally, you must start a server (webassembly can't be loaded
over file://):
-
Javacript:
npx serve _html -
Golang:
go run .