test: Remove comparison to gometalinter in benchmarks (#1732)
This commit is contained in:
parent
747e3aea00
commit
a3c2ed0206
@ -16,7 +16,6 @@ import (
|
|||||||
gops "github.com/mitchellh/go-ps"
|
gops "github.com/mitchellh/go-ps"
|
||||||
"github.com/shirou/gopsutil/v3/process"
|
"github.com/shirou/gopsutil/v3/process"
|
||||||
|
|
||||||
"github.com/golangci/golangci-lint/pkg/config"
|
|
||||||
"github.com/golangci/golangci-lint/test/testshared"
|
"github.com/golangci/golangci-lint/test/testshared"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -36,7 +35,7 @@ func prepareGithubProject(owner, name string) func(*testing.B) {
|
|||||||
_, err := os.Stat(dir)
|
_, err := os.Stat(dir)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
repo := fmt.Sprintf("https://github.com/%s/%s.git", owner, name)
|
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 {
|
if err != nil {
|
||||||
b.Fatalf("can't git clone %s/%s: %s", owner, name, err)
|
b.Fatalf("can't git clone %s/%s: %s", owner, name, err)
|
||||||
}
|
}
|
||||||
@ -56,7 +55,6 @@ func getBenchLintersArgsNoMegacheck() []string {
|
|||||||
"--enable=errcheck",
|
"--enable=errcheck",
|
||||||
"--enable=dupl",
|
"--enable=dupl",
|
||||||
"--enable=ineffassign",
|
"--enable=ineffassign",
|
||||||
"--enable=interfacer",
|
|
||||||
"--enable=unconvert",
|
"--enable=unconvert",
|
||||||
"--enable=goconst",
|
"--enable=goconst",
|
||||||
"--enable=gosec",
|
"--enable=gosec",
|
||||||
@ -69,21 +67,6 @@ func getBenchLintersArgs() []string {
|
|||||||
}, getBenchLintersArgsNoMegacheck()...)
|
}, 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) {
|
func printCommand(cmd string, args ...string) {
|
||||||
if os.Getenv("PRINT_CMD") != "1" {
|
if os.Getenv("PRINT_CMD") != "1" {
|
||||||
return
|
return
|
||||||
@ -96,16 +79,6 @@ func printCommand(cmd string, args ...string) {
|
|||||||
log.Printf("%s %s", cmd, strings.Join(quotedArgs, " "))
|
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 {
|
func getGolangciLintCommonArgs() []string {
|
||||||
return []string{"run", "--no-config", "--issues-exit-code=0", "--deadline=30m", "--disable-all", "--enable=govet"}
|
return []string{"run", "--no-config", "--issues-exit-code=0", "--deadline=30m", "--disable-all", "--enable=govet"}
|
||||||
}
|
}
|
||||||
@ -211,20 +184,6 @@ type runResult struct {
|
|||||||
duration time.Duration
|
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 {
|
func runOne(b *testing.B, run func(*testing.B), progName string) *runResult {
|
||||||
doneCh := make(chan struct{})
|
doneCh := make(chan struct{})
|
||||||
peakMemCh := trackPeakMemoryUsage(b, doneCh, progName)
|
peakMemCh := trackPeakMemoryUsage(b, doneCh, progName)
|
||||||
@ -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()
|
testshared.NewLintRunner(b).Install()
|
||||||
|
|
||||||
type bcase struct {
|
type bcase struct {
|
||||||
@ -252,10 +211,6 @@ func BenchmarkWithGometalinter(b *testing.B) {
|
|||||||
name: "self repo",
|
name: "self repo",
|
||||||
prepare: prepareGithubProject("golangci", "golangci-lint"),
|
prepare: prepareGithubProject("golangci", "golangci-lint"),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "gometalinter repo",
|
|
||||||
prepare: prepareGithubProject("alecthomas", "gometalinter"),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "hugo",
|
name: "hugo",
|
||||||
prepare: prepareGithubProject("gohugoio", "hugo"),
|
prepare: prepareGithubProject("gohugoio", "hugo"),
|
||||||
@ -284,7 +239,12 @@ func BenchmarkWithGometalinter(b *testing.B) {
|
|||||||
for _, bc := range bcases {
|
for _, bc := range bcases {
|
||||||
bc.prepare(b)
|
bc.prepare(b)
|
||||||
lc := getGoLinesTotalCount(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,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user