Skip to content

Commit

Permalink
ci
Browse files Browse the repository at this point in the history
  • Loading branch information
acheronfail committed Dec 14, 2023
1 parent fae1708 commit fae1764
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 98 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Do the thing in CI

on:
push:
branches: ['master']

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
run-all:
runs-on: ubuntu-latest
steps:
# clone
- name: Checkout
uses: actions/checkout@v3
# cache
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
~/.cargo/.crates.toml
~/.cargo/.crates2.json
target/
key: ${{ runner.os }}-cargo
- uses: actions/cache@v3
with:
path: scripts/node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/package-lock.json') }}
# install dependencies
- uses: extractions/setup-just@v1
- uses: oven-sh/setup-bun@v1
- uses: denoland/setup-deno@v1
with:
deno-version: "~1"
- run: just setup
# do the thing
- run: just count
# report
- uses: actions/upload-artifact@v3
with:
name: results
path: results
57 changes: 39 additions & 18 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,50 @@ _default:
just -l

setup:
#!/usr/bin/env bash
set -euxo pipefail
if [ ! -z "${CI:-}" ]; then
sudo apt-get install build-essential cargo clang curl jq moreutils nodejs rustc
cargo install timers
cargo install hyperfine
cargo install ripgrep --features 'pcre2'
fi
cd scripts && npm install
prepare:
rm -rf {{r}} {{b}}
mkdir {{r}} {{b}}

node:
{{t}} node ./count.js 2> {{r}}/node.yml
{{t}} deno run --allow-all ./count.js 2> {{r}}/deno.yml
{{t}} bun run ./count.js 2> {{r}}/bun.yml

python:
{{t}} python3 ./count.py 2> {{r}}/python.yml

c:
gcc -O3 ./count.c -o {{b}}/c-gcc
{{t}} {{b}}/c-gcc 2> {{r}}/gcc.yml
build: prepare
gcc -O3 ./count.c -o {{b}}/c-gcc
clang -O3 ./count.c -o {{b}}/c-clang
{{t}} {{b}}/c-clang 2> {{r}}/clang.yml

rust:
rustc -C opt-level=3 ./count.rs -o {{b}}/rust
{{t}} {{b}}/rust 2> {{r}}/rust.yml

all: prepare node python c rust
node ./scripts/summary.js
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: build
#!/usr/bin/env bash
set -euxo pipefail
for f in {{b}}/*; do
sleep 5
name="$(basename $f)"
out="{{r}}/${name}.json"
if [[ "$name" == *"python"* ]]; then
args="--runs 2"
else
args="--warmup 3"
fi
hyperfine $args --shell=none --export-json "$out" "$f"
jq '.results[0] | del(.exit_codes)' "$out" | sponge "$out"
timers "$f" >/dev/null 2>&1
timers "$f" >/dev/null 2> >(jq '. += {"max_rss":'$(rg -oP '(?:max_rss:\s*)(\d+)' -r '$1')'}' "$out" | sponge "$out")
done
count: run
node ./scripts/summary.js > ./results/table.txt
1 change: 1 addition & 0 deletions scripts/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry=https://registry.npmjs.org/
77 changes: 9 additions & 68 deletions scripts/package-lock.json

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

1 change: 0 additions & 1 deletion scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"type": "module",
"dependencies": {
"human-readable": "^0.2.1",
"js-yaml": "^4.1.0",
"pretty-bytes": "^6.1.1",
"pretty-time": "^1.1.0"
},
Expand Down
21 changes: 10 additions & 11 deletions scripts/summary.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
import { readFile } from 'fs/promises';
import { readdirSync } from 'fs';
import { join } from 'path';
import yaml from 'js-yaml';
import formatTime from 'pretty-time';
import formatSize from 'pretty-bytes';

const resultsDir = './results';
const results = await Promise.all(
readdirSync(resultsDir).map(async (name) => {
const text = await readFile(join(resultsDir, name), 'utf-8');
const json = yaml.load(text.replace(/INFO \[timers\] /g, '').replace(/ -$/gm, ' null'));
const json = JSON.parse(text.replace(/INFO \[timers\] /g, '').replace(/ -$/gm, ' null'));

const rss_split = json['max_rss'].indexOf(' ');
return {
name: [name, json['cmdline']].join(' :: '),
real: parseInt(json['real'].replace('ns', '')),
rss: parseInt(json['max_rss'].substring(0, rss_split)),
rss_fmt: json['max_rss'].substring(rss_split),
name: [name, json.command].join(' :: '),
...json
};
})
);

console.table(
results
.slice()
.sort((a, b) => a.real - b.real)
.map(({ name, real }) => ({ name, real: formatTime(real) }))
.sort((a, b) => a.mean - b.mean)
.map(({ name, mean }) => ({
name,
mean: formatTime(Math.floor(mean * 1_000_000_000), undefined, 5),
}))
);

console.table(
results
.slice()
.sort((a, b) => a.rss - b.rss)
.map(({ name, rss }) => ({ name, rss: formatSize(rss, { minimumFractionDigits: 7 }) }))
.sort((a, b) => a.max_rss - b.max_rss)
.map(({ name, max_rss }) => ({ name, max_rss: formatSize(max_rss, { minimumFractionDigits: 7 }) }))
);

0 comments on commit fae1764

Please sign in to comment.