Skip to content

Commit

Permalink
benchmark
Browse files Browse the repository at this point in the history
fix benchmark

use sh

fix path

bench

bench

get latest artifacts

fix artifact name

farm

complete

farm-linux

replace fnm with farm

bench

specify workflow

permission

permission

permission

permission

permission

bench

executable

run

shell script

permission

use rbenv in github

change min-runs

export env

install rbenv

remove rbenv install -L

add uninstall

fix min-runs

fix min-runs

3 runs

use home path

warmup
  • Loading branch information
TaKO8Ki committed Mar 27, 2021
1 parent ba97ab7 commit 663f53c
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 0 deletions.
90 changes: 90 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Benchmark

on:
push:
branches:
- benchmark

jobs:
build_linux_binary:
name: Build Linux binary
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build static binary
run: |
sudo chown -R 1000:1000 .
docker run --rm -v "$(pwd)":/home/rust/src ekidd/rust-musl-builder:stable \
cargo build --release
sudo chown -R $(whoami):$(whoami) .
- name: Compress binary using UPX
run: |
sudo apt-get install -y upx
upx target/x86_64-unknown-linux-musl/release/farm
- uses: actions/upload-artifact@v2
with:
name: farm-linux
path: target/x86_64-unknown-linux-musl/release/farm

benchmark_on_linux:
name: Benchmark (Linux)
needs: [build_linux_binary]
runs-on: ubuntu-latest
steps:
- uses: octokit/[email protected]
id: get_benchmark_workflows
with:
route: GET /repos/:repository/actions/runs
repository: ${{ github.repository }}
branch: benchmark
status: completed
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: octokit/[email protected]
id: get_latest_artifacts
with:
route: GET /repos/:repository/actions/runs/:workflow_id/artifacts
repository: ${{ github.repository }}
workflow_id: 689152766
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Take the output
run: |
URL=$(echo '${{ steps.get_latest_artifacts.outputs.data }}' | jq -r '.artifacts | map(select(.name == "farm-linux")) | .[0].archive_download_url')
curl -L $URL -H 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' > /tmp/farm-latest.zip
mkdir ~/.farm-latest
unzip -d ~/.farm-latest /tmp/farm-latest.zip
ls -lah ~/.farm-latest
- uses: actions/checkout@v2
- name: Install hyperfine
run: |
wget https://github.com/sharkdp/hyperfine/releases/download/v1.10.0/hyperfine_1.10.0_amd64.deb
sudo dpkg -i hyperfine_1.10.0_amd64.deb
- name: Install rbenv
run: |
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
- uses: actions/download-artifact@v2
with:
name: farm-linux
path: target/release/
- name: Run benchmarks
run: ./benchmarks/run

- name: Read basic.md for the generated report
id: basic_result
uses: juliangruber/read-file-action@v1
with:
path: benchmarks/results/basic.md

- uses: octokit/[email protected]
id: get_latest_release
with:
route: POST /repos/:repository/commits/:commit_sha/comments
repository: ${{ github.repository }}
commit_sha: ${{ github.sha }}
body: |
|
${{ steps.basic_result.outputs.content }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 6 additions & 0 deletions benchmarks/farm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
chmod +x ~/.farm-latest/farm
eval "$(~/.farm-latest/farm init)"
~/.farm-latest/farm install 2.6.5
~/.farm-latest/farm local 2.6.5
ruby -v
9 changes: 9 additions & 0 deletions benchmarks/rbenv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

rm -rf ~/.rbenv/versions/2.6.5

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
rbenv install 2.6.5
rbenv local 2.6.5
ruby -v
37 changes: 37 additions & 0 deletions benchmarks/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

set -e

export FARM_DIR

BASE_DIR="$(dirname "$(realpath "$0")")"
cd "$BASE_DIR" || exit 1

FARM_DIR="$(mktemp -d)"
export PATH="$BASE_DIR/../target/release:$PATH"

mkdir results 2>/dev/null || :

if [ ! -f "$BASE_DIR/../target/release/farm" ]; then
echo "Can't access the release version of farm"
exit 1
fi

if ! command -v hyperfine >/dev/null 2>&1; then
echo "Can't access Hyperfine. Are you sure it is installed?"
echo " if not, visit https://github.com/sharkdp/hyperfine"
exit 1
fi

chmod +x ./farm
chmod +x ./rbenv

hyperfine \
--warmup=2 \
--min-runs=3 \
--time-unit=millisecond \
--export-json="./results/basic.json" \
--export-markdown="./results/basic.md" \
--show-output \
"./farm" \
"./rbenv"

1 comment on commit 663f53c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Command Mean [ms] Min [ms] Max [ms] Relative
./farm 201000.9 ± 875.4 200334.7 201992.4 1.00
./rbenv 203593.8 ± 257.4 203309.2 203810.4 1.01 ± 0.00

Please sign in to comment.