Skip to content

Instantly share code, notes, and snippets.

@zekroTJA
Last active November 17, 2022 08:40
Show Gist options
  • Save zekroTJA/323bc7012c49914b95446b4cd7bd9a18 to your computer and use it in GitHub Desktop.
Save zekroTJA/323bc7012c49914b95446b4cd7bd9a18 to your computer and use it in GitHub Desktop.
Simple benchmark to compare compile times between Rust and Go
#!/bin/bash
# Example Results: https://docs.google.com/spreadsheets/d/1wYMqYTVqrG2nG9ZcBTJFxFwT4VC2Fg5GmGEhmQoP8Ns/edit?usp=sharing
GO_CODE="package main
import \"fmt\"
func main() {
fmt.Println(\"Hello world!\")
}"
RUST_CODE="fn main() {
println!(\"Hello world!\");
}"
GO_IMAGE="golang:alpine"
RUST_IMAGE="rust:alpine"
N_RUNS=$1
[ -z $N_RUNS ] && echo "Please specify the number of runs!" && exit 1
rm results_* || true
echo "$GO_CODE" > main.go
for i in $(seq 0 $(($N_RUNS - 1))); do
echo "Go - Run #${i}"
OUT=$(docker run --rm -v $(pwd)/main.go:/var/code/main.go:ro $GO_IMAGE time go build /var/code/main.go 2>&1 > /dev/null)
TIME=$(echo "${OUT}" | head -n 1 | cut -f2)
echo "$i,$TIME" >> results_go.csv
done
rm main.go
echo "$RUST_CODE" > main.rs
for i in $(seq 0 $(($N_RUNS - 1))); do
echo "Rust - Run #${i}"
OUT=$(docker run --rm -v $(pwd)/main.rs:/var/code/main.rs:ro $RUST_IMAGE time rustc -O /var/code/main.rs 2>&1 > /dev/null)
TIME=$(echo "${OUT}" | head -n 1 | cut -f2)
echo "$i,$TIME" >> results_rust.csv
done
rm main.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment