Skip to content

Commit

Permalink
add zig
Browse files Browse the repository at this point in the history
  • Loading branch information
acheronfail committed Dec 19, 2023
1 parent fae1e4c commit fae194c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 23 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
- ruby
- rust
- scala
- zig
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -49,7 +50,20 @@ jobs:
- uses: denoland/setup-deno@v1
with:
deno-version: "~1"
- run: just setup
- run: |
sudo apt install -y build-essential cargo clang curl gfortran jq kotlin moreutils nodejs rustc scala tar wget xz-utils
cargo install timers
cargo install hyperfine
cargo install ripgrep --features 'pcre2'
mkdir -p /opt/zig && cd $_
wget --quiet -O zig.tar.xz $(curl --silent https://ziglang.org/download/index.json | jq -r '.[keys_unsorted[1]]["x86_64-linux"].tarball')
tar -xvf zig.tar.xz 2>&1 >/dev/null
zig_path="$PWD/$(tar -tf zig.tar.xz | head -n1)"
echo "$zig_path" >> $GITHUB_PATH
export PATH="$PATH:$zig_path"
cd -
# do the thing
- run: just measure ${{ matrix.build }}
# report
Expand All @@ -64,7 +78,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: Download Results
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
path: .
- run: sudo apt-get install nodejs
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ build
results
*.class
*.json
*.o
java/
kotlin/
scala/
Expand Down
7 changes: 7 additions & 0 deletions count.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const std = @import("std");

pub fn main() !void {
var i: u32 = 0;
while (i < 1_000_000_000) : (i += 1) {}
std.debug.print("{}\n", .{i});
}
41 changes: 20 additions & 21 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
_default:
just -l

setup:
#!/usr/bin/env bash
set -euxo pipefail
if [ ! -z "${CI:-}" ]; then
sudo apt-get install build-essential cargo clang curl gfortran jq kotlin moreutils nodejs rustc scala
cargo install timers
cargo install hyperfine
cargo install ripgrep --features 'pcre2'
fi
@_check +CMDS:
echo {{CMDS}} | xargs -n1 sh -c 'if ! command -v $1 >/dev/null 2>&1 /dev/null; then echo "$1 is required!"; exit 1; fi' bash

setup: (_check "npm")
cd scripts && npm install

build what:
Expand Down Expand Up @@ -45,45 +40,49 @@ summary results:

# languages

build-gcc:
build-gcc: (_check "gcc")
gcc -O3 ./count.c
echo './a.out' > CMD

build-clang:
build-clang: (_check "clang")
clang -O3 ./count.c
echo './a.out' > CMD

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

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

build-java:
build-java: (_check "javac java")
javac count.java
echo 'java count' > CMD

build-scala:
build-scala: (_check "scalac scala")
scalac count.scala
echo 'scala count' > CMD

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

build-ruby:
build-ruby: (_check "ruby")
echo 'ruby count.rb' > CMD

build-python3:
build-python3: (_check "python3")
echo 'python3 count.py' > CMD

build-node:
build-node: (_check "node")
echo 'node count.js' > CMD

build-deno:
build-deno: (_check "deno")
echo 'deno run count.js' > CMD

build-bun:
build-bun: (_check "bun")
echo 'bun run count.js' > CMD

build-zig: (_check "zig")
zig build-exe -O ReleaseFast ./count.zig
echo './count' > CMD

0 comments on commit fae194c

Please sign in to comment.