Skip to content

Commit

Permalink
tests: Benchmarks for --files
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpovel committed Mar 8, 2024
1 parent 7d39d8c commit 5722cc3
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ jobs:
tool: cargo-msrv
- run: cargo msrv verify

bench-files:
name: Run benchmarks for `--files` option

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: swatinem/rust-cache@v2
- uses: taiki-e/install-action@v2
with:
tool: hyperfine
- name: Run benchmarks
run: >
./benches/bench-files.sh
build-test-feature-powerset:
name: Build and test feature powerset
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# https://github.com/github/gitignore/blob/main/Rust.gitignore

# From a custom benchmark script
benches/srgn

# While working on new README samples, ignore corresponding files
sample.*

Expand Down
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "benches/django"]
path = benches/django
url = [email protected]:django/django.git
[submodule "benches/kubernetes"]
path = benches/kubernetes
url = [email protected]:kubernetes/kubernetes.git
[submodule "benches/pydantic"]
path = benches/pydantic
url = [email protected]:pydantic/pydantic.git
52 changes: 52 additions & 0 deletions benches/bench-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

setup() {
sudo --validate

command -v hyperfine >/dev/null || cargo install hyperfine

git submodule init
git submodule update

cargo build --release
cp target/release/srgn benches/
}

bench() {
# https://www.kernel.org/doc/Documentation/sysctl/vm.txt:
local wipe_caches='sync; echo 3 | sudo tee /proc/sys/vm/drop_caches'

(
cd benches

for i in \
"python comments py django,pydantic" \
"go comments go kubernetes"
do
# We WANT splitting here: https://stackoverflow.com/a/52228219/11477374
# shellcheck disable=SC2086
set -- $i

local lang="$1"
local query_type="$2"
local file_suffix="$3"
local repos="$4" # Can be a comma-separated list

hyperfine \
--max-runs 3 \
--prepare "$wipe_caches" \
--cleanup "git restore --recurse-submodules {repo}" \
--parameter-list repo "$repos" \
--parameter-list find "e+,[Tt]he" \
--parameter-list replace "_,🙂" \
"./srgn --fail-empty-glob --$lang $query_type --files '{repo}/**/*.$file_suffix' '{find}' '{replace}'"
done
)
}

setup
bench
1 change: 1 addition & 0 deletions benches/django
Submodule django added at 73df8b
1 change: 1 addition & 0 deletions benches/kubernetes
Submodule kubernetes added at 5639f8
1 change: 1 addition & 0 deletions benches/pydantic
Submodule pydantic added at 5e1c55

0 comments on commit 5722cc3

Please sign in to comment.