diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c960a74..00a9066 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,8 +8,23 @@ on: workflow_dispatch: jobs: - run-all: + run: runs-on: ubuntu-latest + strategy: + matrix: + build: + - gcc + - clang + - rust + - fortran + - java + - scala + - kotlin + - ruby + - python3 + - node + - deno + - bun steps: # clone - name: Checkout @@ -37,10 +52,81 @@ jobs: with: deno-version: "~1" - run: just setup - # do the thing - - run: just count + + # build + - if: ${{ matrix.build == "gcc" }} + run: | + gcc -O3 ./count.c + echo './a.out' > CMD + - if: ${{ matrix.build == "clang" }} + run: | + clang -O3 ./count.c + echo './a.out' > CMD + - if: ${{ matrix.build == "rust" }} + run: | + rustc -C opt-level=3 ./count.rs + echo './count' > CMD + - if: ${{ matrix.build == "fortran" }} + run: | + gfortran -O3 ./count.f90 + echo './a.out' > CMD + - if: ${{ matrix.build == "java" }} + run: | + javac count.java + echo 'java Count' > CMD + - if: ${{ matrix.build == "scala" }} + run: | + scalac count.scala + echo 'scala Count' > CMD + - if: ${{ matrix.build == "kotlin" }} + run: | + kotlinc count.kt -include-runtime -d count.jar + echo 'java -jar count.jar' > CMD + - if: ${{ matrix.build == "ruby" }} + run: echo 'ruby count.rb' > CMD + - if: ${{ matrix.build == "python3" }} + run: echo 'python3 count.py' > CMD + - if: ${{ matrix.build == "node" }} + run: echo 'node count.js' > CMD + - if: ${{ matrix.build == "deno" }} + run: echo 'deno run count.js' > CMD + - if: ${{ matrix.build == "bun" }} + run: echo 'bun run count.js' > CMD + + # bench + - run: | + case "$name" in + *"python"*|*"ruby"*) + args="--runs 1" + ;; + *) + args="--warmup 3" + ;; + esac + + out="${{ matrix.build }}.json" + + hyperfine $args --shell=none --export-json "$out" "$(cat CMD)" + jq '.results[0] | del(.exit_codes)' "$out" | sponge "$out" + timers "$f" >/dev/null 2> >(jq '. += {"max_rss":'$(rg -oP '(?:max_rss:\s*)(\d+)' -r '$1')'}' "$out" | sponge "$out") + # report + - run: ls -lah . + - run: ls -lah results - uses: actions/upload-artifact@v3 with: - name: results - path: results \ No newline at end of file + name: "${{ matrix.build }}.json" + path: "results/${{ matrix.build }}" + + report: + needs: ['run'] + runs-on: ubuntu-latest + steps: + - uses: oven-sh/setup-bun@v1 + - name: Download Results + uses: actions/download-artifact@v2 + with: + path: results + - run: ls -lah . + - run: ls -lah results + # TODO: create report \ No newline at end of file diff --git a/count.java b/count.java index 774d674..d2f50ee 100644 --- a/count.java +++ b/count.java @@ -1,4 +1,4 @@ -public class count { +public class Count { public static void main(String[] args){ int i = 0; diff --git a/justfile b/justfile index e505be5..2983b7c 100644 --- a/justfile +++ b/justfile @@ -1,7 +1,3 @@ -t := "timers --time=nano" -r := "results" -b := "build" - _default: just -l @@ -15,55 +11,3 @@ setup: cargo install ripgrep --features 'pcre2' fi cd scripts && npm install - -prepare: - rm -rf {{r}} {{b}} - mkdir {{r}} {{b}} - -build: prepare - gcc -O3 ./count.c -o {{b}}/c-gcc - clang -O3 ./count.c -o {{b}}/c-clang - rustc -C opt-level=3 ./count.rs -o {{b}}/rust - gfortran -O3 ./count.f90 -o {{b}}/fortran - javac count.java -d java - mkdir -p scala && scalac count.scala -d scala - kotlinc count.kt -include-runtime -d kotlin/kotlin.jar - echo "#!/usr/bin/env -S scala -classpath scala Count" > {{b}}/scala - echo "#!/usr/bin/env -S java -jar kotlin/kotlin.jar " > {{b}}/kotlin - echo "#!/usr/bin/env -S java -cp java count " > {{b}}/java - echo "#!/usr/bin/env -S ruby \n$(cat count.rb)" > {{b}}/ruby - echo "#!/usr/bin/env -S python3 \n$(cat count.py)" > {{b}}/python3 - echo "#!/usr/bin/env -S node \n$(cat count.js)" > {{b}}/node - echo "#!/usr/bin/env -S deno run \n$(cat count.js)" > {{b}}/deno - echo "#!/usr/bin/env -S bun \n$(cat count.js)" > {{b}}/bun - for f in {{b}}/*; do chmod +x "$f"; done - -run what: build - {{b}}/{{what}} - -all: build - #!/usr/bin/env bash - set -euxo pipefail - for f in {{b}}/*; do - sleep 5 - - name="$(basename $f)" - out="{{r}}/${name}.json" - - case "$name" in - *"python"*|*"ruby"*) - args="--runs 2" - ;; - *) - args="--warmup 3" - ;; - esac - hyperfine $args --shell=none --export-json "$out" "$f" - - jq '.results[0] | del(.exit_codes)' "$out" | sponge "$out" - timers "$f" >/dev/null 2> >(jq '. += {"max_rss":'$(rg -oP '(?:max_rss:\s*)(\d+)' -r '$1')'}' "$out" | sponge "$out") - done - -count: all - node ./scripts/summary.js > {{r}}/table.txt - cat {{r}}/table.txt \ No newline at end of file