Skip to content

Instantly share code, notes, and snippets.

@jjo
Last active November 16, 2024 14:09
Show Gist options
  • Save jjo/4d9a822b2fc34c0f2d6c663e63a03189 to your computer and use it in GitHub Desktop.
Save jjo/4d9a822b2fc34c0f2d6c663e63a03189 to your computer and use it in GitHub Desktop.
https://benjdd.com/loops/ (from https://x.com/BenjDicken/status/1857449788893286484) in C and Go, Go version built natively and as WASM

Summary:

Lang Target Wall time CPU util MaxRSS obs
C native build 0:01.0s 99% 1.37MiB baseline
Go native build 0:05.48 99% 1.75MiB
Go wasm 0:05.50 99% 54.00MiB ran using wasmer
Go wasm 0:05.64 99% 24.61MiB ran using wasmtime
BUILD: build-c-native/main
+ gcc -O1 -o build-c-native/main main.c
BUILD: build-go-native/main
+ go build -o build-go-native/main main.go
BUILD: build-go-wasm/main.wasm
+ env GOOS=wasip1 GOARCH=wasm go build -o build-go-wasm/main.wasm main.go

RUN: run-c-native/main
+ time ./build-c-native/main
1.09user 0.00system 0:01.09elapsed 99%CPU (0avgtext+0avgdata 1408maxresident)k
0inputs+0outputs (0major+109minor)pagefaults 0swaps

RUN: run-go-native/main
+ time ./build-go-native/main
5.48user 0.02system 0:05.48elapsed 99%CPU (0avgtext+0avgdata 1792maxresident)k
0inputs+0outputs (0major+233minor)pagefaults 0swaps

RUN: run-go-wasm/main.wasm with wasmer
+ cd build-go-wasm/
+ time wasmer run ./main.wasm
5.45user 0.04system 0:05.50elapsed 99%CPU (0avgtext+0avgdata 55296maxresident)k
0inputs+0outputs (0major+7460minor)pagefaults 0swaps

RUN: run-go-wasm/main.wasm with wasmtime
+ cd build-go-wasm/
+ time wasmtime run ./main.wasm
5.61user 0.02system 0:05.64elapsed 99%CPU (0avgtext+0avgdata 25204maxresident)k
0inputs+8outputs (0major+5796minor)pagefaults 0swaps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment