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 fae19ac
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 97 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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
# install dependencies
- uses: extractions/setup-just@v1
- uses: oven-sh/setup-bun@v1
# checks
- run: just setup
- run: just count
48 changes: 31 additions & 17 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,43 @@ _default:
just -l

setup:
#!/usr/bin/env bash
set -euxo pipefail
if [ ! -z "${CI:-}" ]; then
if command -v apt-get >/dev/null 2>&1; then sudo apt-get install build-essential cargo clang curl hyperfine jq moreutils nodejs rustc; fi
if command -v deno >/dev/null 2>&1; then cargo install deno --locked; fi
if command -v rg >/dev/null 2>&1; then cargo install ripgrep --locked; fi
if command -v bun >/dev/null 2>&1; then curl -fsSL https://bun.sh/install | bash; fi
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
echo "#!/usr/bin/env python3 \n$(cat count.py)" >> {{b}}/python3
echo "#!/usr/bin/env node \n$(cat count.js)" >> {{b}}/node
echo "#!/usr/bin/env deno run \n$(cat count.js)" >> {{b}}/deno
echo "#!/usr/bin/env bun \n$(cat count.js)" >> {{b}}/bun
for f in {{b}}/*; do chmod +x "$f"; done

run: build
#!/usr/bin/env bash
for f in {{b}}/*; do
out="{{r}}/$(basename $f).json"
hyperfine \
--warmup 3 \
--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
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
22 changes: 11 additions & 11 deletions scripts/summary.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
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(' ');
console.log(json);
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 fae19ac

Please sign in to comment.