Open
Description
Compared to a Rust generated binary, swiftwasm generates binaries with slower performance and larger size. The results can be evaluated here: https://github.com/hassan-shahbazi/swiftwasm-go/tree/benchmark
Performance
With the same imported and exported functions and the _start, Swift's binary performs almost 85x slower than the Rust one, with 18.350
seconds and 0.214
seconds respectively.
$ # RUST - generate binary.wasm from a rust code
$ cd rust && rustc binary.rs --target wasm32-wasi && cd ../
$ go test ./... -v -race -count 1 -run _Rust
=== RUN TestStartBinary_Rust
Hello, world!
--- PASS: TestStartBinary_Rust (0.07s)
=== RUN TestExportedFunction_Rust
--- PASS: TestExportedFunction_Rust (0.06s)
=== RUN TestImportedFunction_Rust
--- PASS: TestImportedFunction_Rust (0.06s)
PASS
ok github.com/hassan-shahbazi/swiftwasi/src 0.214s
$ # SWIFT - generate binary.wasm from the swift package
$ TOOLCHAIN_PATH=$(cd $(dirname "$(swiftenv which swiftc)") && cd ../share && pwd)
$ cd swift && swift build --triple wasm32-unknown-wasi -c release --toolchain $TOOLCHAIN -Xlinker --export=fetch -Xlinker --export=sum -Xlinker --allow-undefined
$ go test ./... -v -race -count 1 -run _Swift
=== RUN TestStartBinary_Swift
Hello World!
--- PASS: TestStartBinary_Swift (6.42s)
=== RUN TestExportedFunction_Swift
--- PASS: TestExportedFunction_Swift (6.28s)
=== RUN TestImportedFunction_Swift
--- PASS: TestImportedFunction_Swift (5.52s)
PASS
ok github.com/hassan-shahbazi/swiftwasi/src 18.350s
Size
In addition to performance, I can see Swift generated binary is almost 5x larger than the Rust generated binary
$ ls -lh rust | grep wasm
-rwxrwxr-x 1 hassan hassan 1.7M Oct 30 20:33 binary.wasm
$ ls -lh swiftwasm | grep wasm
-rwxrwxr-x 1 hassan hassan 9.8M Oct 26 17:08 binary.wasm
Metadata
Metadata
Assignees
Labels
No labels