Skip to content

Commit

Permalink
split up jobs in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
acheronfail committed Dec 18, 2023
1 parent fae107b commit fae1e1d
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 56 deletions.
39 changes: 35 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,23 @@ on:
workflow_dispatch:

jobs:
run-all:
run:
runs-on: ubuntu-latest
strategy:
matrix:
build:
- bun
- clang
- deno
- fortran
- gcc
- java
- kotlin
- node
- python3
- ruby
- rust
- scala
steps:
# clone
- name: Checkout
Expand Down Expand Up @@ -37,10 +52,26 @@ jobs:
with:
deno-version: "~1"
- run: just setup

# do the thing
- run: just count
- run: just measure ${{ matrix.build }}

# report
- uses: actions/upload-artifact@v3
with:
name: results
path: results
path: "${{ matrix.build }}.json"

report:
needs: ['run']
runs-on: ubuntu-latest
steps:
- uses: oven-sh/setup-bun@v1
- name: Download Results
uses: actions/download-artifact@v2
with:
path: .
- run: apt-get install nodejs
- run: |
cd scripts
npm install
node ./summary.js --results ../artifact
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ results
*.class
java/
kotlin/
scala/
scala/
CMD
4 changes: 2 additions & 2 deletions count.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object Count {
object count {
def main(args: Array[String]) = {
var num = 0
while (num < 1_000_000_000) {
while (num < 1000000000) {
num += 1
}

Expand Down
114 changes: 67 additions & 47 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
t := "timers --time=nano"
r := "results"
b := "build"

_default:
just -l

Expand All @@ -16,54 +12,78 @@ setup:
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
build what:
just build-{{what}}

run what:
just build {{what}}
@$(cat CMD)

measure what:
#!/usr/bin/env bash
set -euxo pipefail
for f in {{b}}/*; do
sleep 5
name="$(basename $f)"
out="{{r}}/${name}.json"
just build {{what}}

case "$name" in
*"python"*|*"ruby"*)
args="--runs 2"
;;
*)
case "{{what}}" in
*"python"*|*"ruby"*)
args="--runs 1"
;;
*)
args="--warmup 3"
;;
esac
hyperfine $args --shell=none --export-json "$out" "$f"
esac

out="{{what}}.json"

hyperfine $args --shell=none --export-json "$out" "$(cat CMD)"
jq '.results[0] | del(.exit_codes)' "$out" | sponge "$out"
timers $(cat CMD) >/dev/null 2> >(jq '. += {"max_rss":'$(rg -oP '(?:max_rss:\s*)(\d+)' -r '$1')'}' "$out" | sponge "$out")

summary results:
cd scripts && node ./summary.js --results ..

# languages

build-gcc:
gcc -O3 ./count.c
echo './a.out' > CMD

build-clang:
clang -O3 ./count.c
echo './a.out' > CMD

build-rust:
rustc -C opt-level=3 ./count.rs
echo './count' > CMD

build-fortran:
gfortran -O3 ./count.f90
echo './a.out' > CMD

build-java:
javac count.java
echo 'java count' > CMD

build-scala:
scalac count.scala
echo 'scala count' > CMD

build-kotlin:
kotlinc count.kt -include-runtime -d count.jar
echo 'java -jar count.jar' > CMD

build-ruby:
echo 'ruby count.rb' > CMD

build-python3:
echo 'python3 count.py' > CMD

build-node:
echo 'node count.js' > 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")
done
build-deno:
echo 'deno run count.js' > CMD

count: all
node ./scripts/summary.js > {{r}}/table.txt
cat {{r}}/table.txt
build-bun:
echo 'bun run count.js' > CMD
19 changes: 18 additions & 1 deletion scripts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
"type": "module",
"dependencies": {
"human-readable": "^0.2.1",
"minimist": "^1.2.8",
"pretty-bytes": "^6.1.1",
"pretty-time": "^1.1.0"
},
"devDependencies": {
"@types/minimist": "^1.2.5",
"@types/node": "^20.10.4"
}
}
6 changes: 5 additions & 1 deletion scripts/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ import { readdirSync } from 'fs';
import { join } from 'path';
import formatTime from 'pretty-time';
import formatSize from 'pretty-bytes';
import minimist from 'minimist';

const args = minimist(process.argv.slice(2));
const resultsDir = args.results;
if (!resultsDir) throw new Error('Please pass --results');

const resultsDir = './results';
const results = await Promise.all(
readdirSync(resultsDir)
.filter((name) => name.endsWith('.json'))
Expand Down

0 comments on commit fae1e1d

Please sign in to comment.