Skip to content
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

Remove comparison to gometalinter in benchmarks #1732

Merged
merged 12 commits into from Feb 21, 2021
56 changes: 8 additions & 48 deletions test/bench/bench_test.go
Expand Up @@ -16,7 +16,6 @@ import (
gops "github.com/mitchellh/go-ps"
"github.com/shirou/gopsutil/v3/process"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/test/testshared"
)

Expand All @@ -36,7 +35,7 @@ func prepareGithubProject(owner, name string) func(*testing.B) {
_, err := os.Stat(dir)
if os.IsNotExist(err) {
repo := fmt.Sprintf("https://github.com/%s/%s.git", owner, name)
err = exec.Command("git", "clone", repo).Run()
err = exec.Command("git", "clone", repo, dir).Run()
if err != nil {
b.Fatalf("can't git clone %s/%s: %s", owner, name, err)
}
Expand All @@ -56,7 +55,6 @@ func getBenchLintersArgsNoMegacheck() []string {
"--enable=errcheck",
"--enable=dupl",
"--enable=ineffassign",
"--enable=interfacer",
"--enable=unconvert",
"--enable=goconst",
"--enable=gosec",
Expand All @@ -69,21 +67,6 @@ func getBenchLintersArgs() []string {
}, getBenchLintersArgsNoMegacheck()...)
}

func getGometalinterCommonArgs() []string {
return []string{
"--deadline=30m",
"--skip=testdata",
"--skip=builtin",
"--vendor",
"--cyclo-over=30",
"--dupl-threshold=150",
"--exclude", fmt.Sprintf("(%s)", strings.Join(config.GetDefaultExcludePatternsStrings(), "|")),
"--disable-all",
"--enable=vet",
"--enable=vetshadow",
}
}

func printCommand(cmd string, args ...string) {
if os.Getenv("PRINT_CMD") != "1" {
return
Expand All @@ -96,16 +79,6 @@ func printCommand(cmd string, args ...string) {
log.Printf("%s %s", cmd, strings.Join(quotedArgs, " "))
}

func runGometalinter(b *testing.B) {
args := []string{}
args = append(args, getGometalinterCommonArgs()...)
args = append(args, getBenchLintersArgs()...)
args = append(args, "./...")

printCommand("gometalinter", args...)
_ = exec.Command("gometalinter", args...).Run()
}

func getGolangciLintCommonArgs() []string {
return []string{"run", "--no-config", "--issues-exit-code=0", "--deadline=30m", "--disable-all", "--enable=govet"}
}
Expand Down Expand Up @@ -211,20 +184,6 @@ type runResult struct {
duration time.Duration
}

func compare(b *testing.B, gometalinterRun, golangciLintRun func(*testing.B), repoName, mode string, kLOC int) {
gometalinterRes := runOne(b, gometalinterRun, "gometalinter")
golangciLintRes := runOne(b, golangciLintRun, "golangci-lint")

if mode != "" {
mode = " " + mode
}
log.Printf("%s (%d kLoC): golangci-lint%s: time: %s, %.1f times faster; memory: %dMB, %.1f times less",
repoName, kLOC, mode,
golangciLintRes.duration, gometalinterRes.duration.Seconds()/golangciLintRes.duration.Seconds(),
golangciLintRes.peakMemMB, float64(gometalinterRes.peakMemMB)/float64(golangciLintRes.peakMemMB),
)
}

func runOne(b *testing.B, run func(*testing.B), progName string) *runResult {
doneCh := make(chan struct{})
peakMemCh := trackPeakMemoryUsage(b, doneCh, progName)
Expand All @@ -240,7 +199,7 @@ func runOne(b *testing.B, run func(*testing.B), progName string) *runResult {
}
}

func BenchmarkWithGometalinter(b *testing.B) {
func BenchmarkGolangciLint(b *testing.B) {
testshared.NewLintRunner(b).Install()

type bcase struct {
Expand All @@ -252,10 +211,6 @@ func BenchmarkWithGometalinter(b *testing.B) {
name: "self repo",
prepare: prepareGithubProject("golangci", "golangci-lint"),
},
{
name: "gometalinter repo",
prepare: prepareGithubProject("alecthomas", "gometalinter"),
},
{
name: "hugo",
prepare: prepareGithubProject("gohugoio", "hugo"),
Expand Down Expand Up @@ -284,7 +239,12 @@ func BenchmarkWithGometalinter(b *testing.B) {
for _, bc := range bcases {
bc.prepare(b)
lc := getGoLinesTotalCount(b)
result := runOne(b, runGolangciLintForBench, "golangci-lint")

compare(b, runGometalinter, runGolangciLintForBench, bc.name, "", lc/1000)
log.Printf("%s (%d kLoC): time: %s, memory: %dMB",
bc.name, lc/1000,
result.duration,
result.peakMemMB,
)
}
}