Skip to content

Commit 596a70e

Browse files
committed
dev: add targets to benchmark a linter
1 parent f738736 commit 596a70e

File tree

4 files changed

+97
-0
lines changed

4 files changed

+97
-0
lines changed

Makefile

+14
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ fast_check_generated:
6060
git checkout -- go.mod go.sum # can differ between go1.16 and go1.17
6161
git diff --exit-code # check no changes
6262

63+
# Benchmark
64+
65+
# Benchmark with a local version
66+
# LINTER=gosec VERSION=v1.59.0 make bench_local
67+
bench_local:
68+
./scripts/bench/bench_local.sh $(LINTER) $(VERSION)
69+
.PHONY: bench_local
70+
71+
# Benchmark between 2 existing versions
72+
# LINTER=gosec VERSION_OLD=v1.58.2 VERSION_NEW=v1.59.0 make bench_version
73+
bench_version:
74+
./scripts/bench/bench_version.sh $(LINTER) $(VERSION_OLD) $(VERSION_NEW)
75+
.PHONY: bench_version
76+
6377
# Non-PHONY targets (real files)
6478

6579
$(BINARY): FORCE

scripts/bench/bench_local.sh

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash -e
2+
3+
# Benchmark with a local version
4+
# Usage: ./scripts/bench/bench_local.sh gosec v1.59.0
5+
6+
# ex: gosec
7+
LINTER_NAME=$1
8+
9+
# ex: v1.59.0
10+
GCIL_VERSION=$2
11+
12+
## Download version
13+
14+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./temp-${GCIL_VERSION}/ ${GCIL_VERSION}
15+
16+
mv temp-${GCIL_VERSION}/golangci-lint ./golangci-lint-${GCIL_VERSION}
17+
rm -rf temp-${GCIL_VERSION}
18+
19+
## Build local version
20+
21+
make build
22+
23+
## Run
24+
25+
hyperfine \
26+
--prepare 'golangci-lint cache clean' "./golangci-lint run --print-issued-lines=false --enable-only ${LINTER_NAME}" \
27+
--prepare './golangci-lint cache clean' "./golangci-lint-${GCIL_VERSION} run --print-issued-lines=false --enable-only ${LINTER_NAME}"
28+
29+
## Clean
30+
31+
rm ./golangci-lint-${GCIL_VERSION}

scripts/bench/bench_version.sh

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash -e
2+
3+
# Benchmark between 2 existing versions
4+
# Usage: ./scripts/bench/bench_version.sh gosec v1.58.1 v1.58.2
5+
6+
# ex: gosec
7+
LINTER_NAME=$1
8+
9+
# ex: v1.58.1
10+
GCIL_VERSION_ONE=$2
11+
# ex: v1.58.2
12+
GCIL_VERSION_TWO=$3
13+
14+
## GCIL_VERSION_ONE
15+
16+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./temp-${GCIL_VERSION_ONE} ${GCIL_VERSION_ONE}
17+
18+
mv temp-${GCIL_VERSION_ONE}/golangci-lint ./golangci-lint-${GCIL_VERSION_ONE}
19+
rm -rf temp-${GCIL_VERSION_ONE}
20+
21+
## GCIL_VERSION_TWO
22+
23+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./temp-${GCIL_VERSION_TWO} ${GCIL_VERSION_TWO}
24+
25+
mv temp-${GCIL_VERSION_TWO}/golangci-lint ./golangci-lint-${GCIL_VERSION_TWO}
26+
rm -rf temp-${GCIL_VERSION_TWO}
27+
28+
## Run
29+
30+
hyperfine \
31+
--prepare 'golangci-lint cache clean' "./golangci-lint-${GCIL_VERSION_ONE} run --issues-exit-code 0 --print-issued-lines=false --enable-only ${LINTER_NAME}" \
32+
--prepare './golangci-lint cache clean' "./golangci-lint-${GCIL_VERSION_TWO} run --issues-exit-code 0 --print-issued-lines=false --enable-only ${LINTER_NAME}"
33+
34+
## Clean
35+
36+
rm ./golangci-lint-${GCIL_VERSION_ONE}
37+
rm ./golangci-lint-${GCIL_VERSION_TWO}

scripts/bench/readme.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Benchmarks
2+
3+
The script use [Hyperfine](https://github.com/sharkdp/hyperfine) to benchmark the command line of golangci-lint.
4+
5+
## Benchmark one linter: with a local version
6+
7+
```bash
8+
LINTER=gosec VERSION=v1.59.0 make bench_local
9+
```
10+
11+
## Benchmark one linter: between 2 existing versions
12+
13+
```bash
14+
LINTER=gosec VERSION_OLD=v1.58.2 VERSION_NEW=v1.59.0 make bench_version
15+
```

0 commit comments

Comments
 (0)