Skip to content

dev: add targets to benchmark a linter #4761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ fast_check_generated:
git checkout -- go.mod go.sum # can differ between go1.16 and go1.17
git diff --exit-code # check no changes

# Benchmark

# Benchmark with a local version
# LINTER=gosec VERSION=v1.59.0 make bench_local
bench_local: hyperfine
@./scripts/bench/bench_local.sh $(LINTER) $(VERSION)
.PHONY: bench_local

# Benchmark between 2 existing versions
# LINTER=gosec VERSION_OLD=v1.58.2 VERSION_NEW=v1.59.0 make bench_version
bench_version: hyperfine
@./scripts/bench/bench_version.sh $(LINTER) $(VERSION_OLD) $(VERSION_NEW)
.PHONY: bench_version

hyperfine:
@which hyperfines > /dev/null || (echo "Please install hyperfine https://github.com/sharkdp/hyperfine#installation" && exit 1)
.PHONY: hyperfine

# Non-PHONY targets (real files)

$(BINARY): FORCE
Expand Down
41 changes: 41 additions & 0 deletions scripts/bench/bench_local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash -e

# Benchmark with a local version
# Usage: ./scripts/bench/bench_local.sh gosec v1.59.0

# ex: gosec
LINTER=$1

# ex: v1.59.0
VERSION=$2

## Clean

function cleanBinaries() {
echo "Clean binaries"
rm "./golangci-lint-${VERSION}"
rm ./golangci-lint
}

trap cleanBinaries EXIT

## Download version

curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "./temp-${VERSION}" "${VERSION}"

mv "temp-${VERSION}/golangci-lint" "./golangci-lint-${VERSION}"
rm -rf "temp-${VERSION}"

## Build local version

make build

## Run

hyperfine \
--prepare './golangci-lint cache clean' "./golangci-lint run --issues-exit-code 0 --print-issued-lines=false --enable-only ${LINTER}" \
--prepare "./golangci-lint-${VERSION} cache clean" "./golangci-lint-${VERSION} run --issues-exit-code 0 --print-issued-lines=false --enable-only ${LINTER}"

## Clean

rm "./golangci-lint-${VERSION}"
47 changes: 47 additions & 0 deletions scripts/bench/bench_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash -e

# Benchmark between 2 existing versions
# Usage: ./scripts/bench/bench_version.sh gosec v1.58.1 v1.58.2

# ex: gosec
LINTER="$1"

# ex: v1.58.1
VERSION_OLD="$2"
# ex: v1.58.2
VERSION_NEW="$3"

## Clean

function cleanBinaries() {
echo "Clean binaries"
rm "./golangci-lint-${VERSION_OLD}"
rm "./golangci-lint-${VERSION_NEW}"
}

trap cleanBinaries EXIT

## Install

function install() {
local VERSION=$1

curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "./temp-${VERSION}" "${VERSION}"

mv "temp-${VERSION}/golangci-lint" "./golangci-lint-${VERSION}"
rm -rf "temp-${VERSION}"
}

## VERSION_OLD

install "${VERSION_OLD}"

## VERSION_NEW

install "${VERSION_NEW}"

## Run

hyperfine \
--prepare "./golangci-lint-${VERSION_OLD} cache clean" "./golangci-lint-${VERSION_OLD} run --issues-exit-code 0 --print-issued-lines=false --enable-only ${LINTER}" \
--prepare "./golangci-lint-${VERSION_NEW} cache clean" "./golangci-lint-${VERSION_NEW} run --issues-exit-code 0 --print-issued-lines=false --enable-only ${LINTER}"
15 changes: 15 additions & 0 deletions scripts/bench/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Benchmarks

The script use [Hyperfine](https://github.com/sharkdp/hyperfine) to benchmark the command line of golangci-lint.

## Benchmark one linter: with a local version

```bash
LINTER=gosec VERSION=v1.59.0 make bench_local
```

## Benchmark one linter: between 2 existing versions

```bash
LINTER=gosec VERSION_OLD=v1.58.1 VERSION_NEW=v1.59.0 make bench_version
```
Loading