Skip to content

Instantly share code, notes, and snippets.

@zekroTJA
Last active November 17, 2022 08:40
Show Gist options
  • Select an option

  • Save zekroTJA/323bc7012c49914b95446b4cd7bd9a18 to your computer and use it in GitHub Desktop.

Select an option

Save zekroTJA/323bc7012c49914b95446b4cd7bd9a18 to your computer and use it in GitHub Desktop.

Revisions

  1. zekroTJA revised this gist Nov 17, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions bench.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    #!/bin/bash

    # Example Results: https://docs.google.com/spreadsheets/d/1wYMqYTVqrG2nG9ZcBTJFxFwT4VC2Fg5GmGEhmQoP8Ns/edit?usp=sharing

    GO_CODE="package main
    import \"fmt\"
    func main() {
  2. zekroTJA revised this gist Nov 17, 2022. No changes.
  3. zekroTJA created this gist Nov 17, 2022.
    38 changes: 38 additions & 0 deletions bench.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    #!/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