#!/bin/bash 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