| 1 | package spdxexpscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src go1.24 fmt/" |
| 5 | "testingscip-go gomod github.com/golang/go/src go1.24 testing/" |
| 6 | ) |
| 7 | |
| 8 | type validateLicensesBenchmarkScenarioscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/validateLicensesBenchmarkScenario# struct { |
| 9 | namescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/validateLicensesBenchmarkScenario#name. string |
| 10 | testLicensesscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/validateLicensesBenchmarkScenario#testLicenses. []string |
| 11 | } |
| 12 | |
| 13 | var validateLicensesBenchmarkScenariosscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/validateLicensesBenchmarkScenarios. = []validateLicensesBenchmarkScenarioscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/validateLicensesBenchmarkScenario#{ |
| 14 | // Scenario order is used as-is in the summary table. |
| 15 | {"MIT--exact", []string{"MIT"}}, |
| 16 | {"mit--caseinsensitive", []string{"mit"}}, |
| 17 | {"mit--extra-space", []string{" MIT "}}, |
| 18 | {"Apache-2.0--active-early", []string{"Apache-2.0"}}, |
| 19 | {"Zed--active-end", []string{"Zed"}}, |
| 20 | {"MIT AND Apache-2.0--complex", []string{"MIT", "Apache-2.0"}}, |
| 21 | {"MIT AND Apache-2.0 OR Zed--complex", []string{"MIT", "Apache-2.0", "Zed"}}, |
| 22 | {"BSD-2-Clause-FreeBSD--deprecated", []string{"BSD-2-Clause-FreeBSD"}}, |
| 23 | {"GPL-2.0-or-later--range", []string{"GPL-2.0-or-later"}}, |
| 24 | {"Apache-1.0+--plus-range", []string{"Apache-1.0+"}}, |
| 25 | {"LicenseRef-scancode-adobe-postscript", []string{"LicenseRef-scancode-adobe-postscript"}}, |
| 26 | {"DocumentRef-spdx-tool-1.2:LicenseRef-MIT-Style-2", []string{"DocumentRef-spdx-tool-1.2:LicenseRef-MIT-Style-2"}}, |
| 27 | } |
| 28 | |
| 29 | func BenchmarkValidateLicensesscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/BenchmarkValidateLicenses().(b *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Bscip-go gomod github.com/golang/go/src go1.24 testing/B#) { |
| 30 | for _, scenario := range validateLicensesBenchmarkScenariosscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/validateLicensesBenchmarkScenarios. { |
| 31 | scenario := scenario |
| 32 | b.Runscip-go gomod github.com/golang/go/src go1.24 testing/B#Run().(scenario.namescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/validateLicensesBenchmarkScenario#name., func(b *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Bscip-go gomod github.com/golang/go/src go1.24 testing/B#) { |
| 33 | benchmarkValidateLicensesScenarioscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/benchmarkValidateLicensesScenario().(b, scenario.testLicensesscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/validateLicensesBenchmarkScenario#testLicenses.) |
| 34 | }) |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | func benchmarkValidateLicensesScenarioscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/benchmarkValidateLicensesScenario().(b *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Bscip-go gomod github.com/golang/go/src go1.24 testing/B#, licenses []string) { |
| 39 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.24 testing/B#ReportAllocs().() |
| 40 | b.ResetTimerscip-go gomod github.com/golang/go/src go1.24 testing/B#ResetTimer().() |
| 41 | |
| 42 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.24 testing/B#N.; i++ { |
| 43 | valid, invalidLicenses := ValidateLicensesscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/ValidateLicenses().(licenses) |
| 44 | if !valid || len(invalidLicenses) != 0 { |
| 45 | b.Fatalfscip-go gomod github.com/golang/go/src go1.24 testing/common#Fatalf().("ValidateLicenses(%v) returned valid=%v invalid=%v", licenses, valid, invalidLicenses) |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | func computeValidateLicensesBenchmarkTableRowsscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/computeValidateLicensesBenchmarkTableRows().(repeats int) []benchmarkTableRowscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/benchmarkTableRow# { |
| 51 | rows := make([]benchmarkTableRowscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/benchmarkTableRow#, 0, len(validateLicensesBenchmarkScenariosscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/validateLicensesBenchmarkScenarios.)) |
| 52 | |
| 53 | for _, scenario := range validateLicensesBenchmarkScenariosscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/validateLicensesBenchmarkScenarios. { |
| 54 | scenario := scenario |
| 55 | avg := runBenchmarkNsAvgscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/runBenchmarkNsAvg().(repeats, func(b *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Bscip-go gomod github.com/golang/go/src go1.24 testing/B#) { |
| 56 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.24 testing/B#ReportAllocs().() |
| 57 | b.ResetTimerscip-go gomod github.com/golang/go/src go1.24 testing/B#ResetTimer().() |
| 58 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.24 testing/B#N.; i++ { |
| 59 | valid, invalidLicenses := ValidateLicensesscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/ValidateLicenses().(scenario.testLicensesscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/validateLicensesBenchmarkScenario#testLicenses.) |
| 60 | if !valid || len(invalidLicenses) != 0 { |
| 61 | panic(fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Sprintf().("ValidateLicenses scenario %q failed: valid=%v invalid=%v", scenario.namescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/validateLicensesBenchmarkScenario#name., valid, invalidLicenses)) |
| 62 | } |
| 63 | } |
| 64 | }) |
| 65 | rows = append(rows, benchmarkTableRowscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/benchmarkTableRow#{labelscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/benchmarkTableRow#label.: scenario.namescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/validateLicensesBenchmarkScenario#name., nsOpAvgscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/benchmarkTableRow#nsOpAvg.: avg}) |
| 66 | } |
| 67 | |
| 68 | return rows |
| 69 | } |