diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 0000000..9002b03 --- /dev/null +++ b/.github/workflows/benchmark.yml @@ -0,0 +1,181 @@ +name: Benchmark + +on: + push: + branches: + - benchmark + +jobs: + build_linux_binary: + name: Build Linux binary + runs-on: ${{ matrix.os }} + env: + CARGO: cargo + TARGET_DIR: ./target + RUST_BACKTRACE: 1 + strategy: + matrix: + build: [linux] + include: + - build: linux + os: ubuntu-18.04 + rust: stable + target: x86_64-unknown-linux-musl + steps: + - uses: actions/checkout@v2 + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + profile: minimal + override: true + target: ${{ matrix.target }} + + - name: Use Cross + run: | + cargo install cross + echo "CARGO=cross" >> $GITHUB_ENV + echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV + echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV + + - name: Show command used for Cargo + run: | + echo "cargo command is: ${{ env.CARGO }}" + echo "target flag is: ${{ env.TARGET_FLAGS }}" + echo "target dir is: ${{ env.TARGET_DIR }}" + + - name: Build static binary + run: ${{ env.CARGO }} build ${{ env.TARGET_FLAGS }} --verbose --release + + - uses: actions/upload-artifact@v2 + with: + name: frum-linux + path: target/x86_64-unknown-linux-musl/release/frum + + benchmark_init_on_linux: + name: Benchmark init (Linux) + needs: [build_linux_binary] + runs-on: ubuntu-latest + steps: + - uses: octokit/request-action@v2.x + 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/request-action@v2.x + id: get_latest_release + with: + route: GET /repos/:repository/releases/latest + repository: ${{ github.repository }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Take the output + run: | + URL=$(echo '${{ steps.get_latest_release.outputs.data }}' | jq -r '.assets | map(select(.name | endswith("x86_64-unknown-linux-musl.tar.gz"))) | .[0].browser_download_url') + echo $URL + curl -L $URL -H 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' > /tmp/frum-latest.tar.gz + mkdir ~/.frum-latest + tar -zxvf /tmp/frum-latest.tar.gz -C ~/.frum-latest --strip-components=1 + ls -lah ~/.frum-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: frum-linux + path: target/release/ + - name: Run benchmarks + run: ./benchmarks/run_init + + - run: lscpu + + - 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/request-action@v2.x + 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 }} + + benchmark_all_on_linux: + name: Benchmark all (Linux) + needs: [build_linux_binary] + runs-on: ubuntu-latest + steps: + - uses: octokit/request-action@v2.x + 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/request-action@v2.x + id: get_latest_release + with: + route: GET /repos/:repository/releases/latest + repository: ${{ github.repository }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Take the output + run: | + URL=$(echo '${{ steps.get_latest_release.outputs.data }}' | jq -r '.assets | map(select(.name | endswith("x86_64-unknown-linux-musl.tar.gz"))) | .[0].browser_download_url') + echo $URL + curl -L $URL -H 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' > /tmp/frum-latest.tar.gz + mkdir ~/.frum-latest + tar -zxvf /tmp/frum-latest.tar.gz -C ~/.frum-latest --strip-components=1 + ls -lah ~/.frum-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: frum-linux + path: target/release/ + - name: Run benchmarks + run: ./benchmarks/run + + - run: lscpu + + - 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/request-action@v2.x + 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 }} diff --git a/benchmarks/frum b/benchmarks/frum new file mode 100755 index 0000000..d028f09 --- /dev/null +++ b/benchmarks/frum @@ -0,0 +1,6 @@ +#!/bin/bash + +eval "$(~/.frum-latest/frum init)" +~/.frum-latest/frum install 2.6.5 +~/.frum-latest/frum local 2.6.5 +ruby -v diff --git a/benchmarks/frum_reason b/benchmarks/frum_reason new file mode 100644 index 0000000..5c03fca --- /dev/null +++ b/benchmarks/frum_reason @@ -0,0 +1,6 @@ +#!/bin/bash + +eval "$(frum init)" +frum install 2.6.5 +frum local 2.6.5 +ruby -v diff --git a/benchmarks/rbenv b/benchmarks/rbenv new file mode 100755 index 0000000..219706b --- /dev/null +++ b/benchmarks/rbenv @@ -0,0 +1,6 @@ +#!/bin/bash + +eval "$(rbenv init -)" +rbenv install 2.6.5 +rbenv local 2.6.5 +ruby -v diff --git a/benchmarks/run b/benchmarks/run new file mode 100755 index 0000000..cb194d4 --- /dev/null +++ b/benchmarks/run @@ -0,0 +1,54 @@ +# #!/bin/bash + +set -e + +export frum_DIR + +BASE_DIR="$(dirname "$(realpath "$0")")" +cd "$BASE_DIR" || exit 1 + +frum_DIR="$(mktemp -d)" +export PATH="$BASE_DIR/../target/release:$PATH" + +mkdir results 2>/dev/null || : + +if [ ! -f "$BASE_DIR/../target/release/frum" ]; then + echo "Can't access the release version of frum" + 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 ./frum +chmod +x ./frum_reason +chmod +x ./rbenv +chmod +x ~/.frum-latest/frum +chmod +x ../target/release/frum + +export PATH="$HOME/.rbenv/bin:$PATH" +export PATH="$HOME/.rbenv/shims:$PATH" + +# command exists? +~/.frum-latest/frum -V +frum -V +rbenv -v +frum install 2.6.5 +rbenv install 2.6.5 +frum global 2.6.5 +rbenv global 2.6.5 + +hyperfine \ + --warmup 2 \ + --min-runs=20 \ + --time-unit=millisecond \ + --export-json="./results/basic.json" \ + --export-markdown="./results/basic.md" \ + --show-output \ + --prepare 'rm -rf ~/.rbenv/versions/2.6.5 ~/.frum/versions/2.6.5' \ + "./rbenv" \ + "./frum" \ + "./frum_reason" diff --git a/benchmarks/run_init b/benchmarks/run_init new file mode 100755 index 0000000..c35ac7d --- /dev/null +++ b/benchmarks/run_init @@ -0,0 +1,51 @@ +# #!/bin/bash + +set -e + +export frum_DIR + +BASE_DIR="$(dirname "$(realpath "$0")")" +cd "$BASE_DIR" || exit 1 + +frum_DIR="$(mktemp -d)" +export PATH="$BASE_DIR/../target/release:$PATH" + +mkdir results 2>/dev/null || : + +if [ ! -f "$BASE_DIR/../target/release/frum" ]; then + echo "Can't access the release version of frum" + 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 ~/.frum-latest/frum +chmod +x ../target/release/frum + +export PATH="$HOME/.rbenv/bin:$PATH" +export PATH="$HOME/.rbenv/shims:$PATH" + +# command exists? +~/.frum-latest/frum -V +frum -V +rbenv -v +frum install 2.6.5 +rbenv install 2.6.5 +frum global 2.6.5 +rbenv global 2.6.5 + +hyperfine \ + --warmup 2 \ + --min-runs=20 \ + --time-unit=millisecond \ + --export-json="./results/basic.json" \ + --export-markdown="./results/basic.md" \ + --show-output \ + --prepare 'rm -rf ~/.rbenv/versions/2.6.5 ~/.frum/versions/2.6.5' \ + 'eval "$(rbenv init -)"' \ + 'eval "$(frum init)"' \ + 'eval "$(~/.frum-latest/frum init)"' \ diff --git a/src/commands/install.rs b/src/commands/install.rs index f1937d0..0d22666 100644 --- a/src/commands/install.rs +++ b/src/commands/install.rs @@ -227,6 +227,8 @@ fn build_package( }; debug!("make install"); let make_install = Command::new("make") + .arg("-j") + .arg(&num_cpus::get().to_string()) .arg("install") .current_dir(¤t_dir) .output()