diff --git a/cache/httpcache/httpcache_test.go b/cache/httpcache/httpcache_test.go index 60c07d056..737dff239 100644 --- a/cache/httpcache/httpcache_test.go +++ b/cache/httpcache/httpcache_test.go @@ -52,7 +52,7 @@ func TestDefaultConfig(t *testing.T) { func TestDecodeConfigInjectsDefaultAndCompiles(t *testing.T) { c := qt.New(t) - cfg, err := DecodeConfig(config.BaseConfig{}, map[string]interface{}{}) + cfg, err := DecodeConfig(config.BaseConfig{}, map[string]any{}) c.Assert(err, qt.IsNil) c.Assert(cfg, qt.DeepEquals, DefaultConfig) diff --git a/commands/server.go b/commands/server.go index 82b18c608..db82defc9 100644 --- a/commands/server.go +++ b/commands/server.go @@ -1035,7 +1035,6 @@ func (c *serverCommand) serve() error { defer cancel() wg2, ctx := errgroup.WithContext(ctx) for _, srv := range servers { - srv := srv wg2.Go(func() error { return srv.Shutdown(ctx) }) diff --git a/common/hashing/hashing_test.go b/common/hashing/hashing_test.go index 105b6d8b5..8a165786a 100644 --- a/common/hashing/hashing_test.go +++ b/common/hashing/hashing_test.go @@ -38,7 +38,6 @@ func TestXxHashFromReaderPara(t *testing.T) { var wg sync.WaitGroup for i := range 10 { - i := i wg.Add(1) go func() { defer wg.Done() @@ -75,8 +74,8 @@ func TestXxHashFromStringHexEncoded(t *testing.T) { func BenchmarkXXHashFromReader(b *testing.B) { r := strings.NewReader("Hello World") - b.ResetTimer() - for i := 0; i < b.N; i++ { + + for b.Loop() { XXHashFromReader(r) r.Seek(0, 0) } @@ -84,16 +83,16 @@ func BenchmarkXXHashFromReader(b *testing.B) { func BenchmarkXXHashFromString(b *testing.B) { s := "Hello World" - b.ResetTimer() - for i := 0; i < b.N; i++ { + + for b.Loop() { XXHashFromString(s) } } func BenchmarkXXHashFromStringHexEncoded(b *testing.B) { s := "The quick brown fox jumps over the lazy dog" - b.ResetTimer() - for i := 0; i < b.N; i++ { + + for b.Loop() { XxHashFromStringHexEncoded(s) } } @@ -136,7 +135,7 @@ func BenchmarkHashString(b *testing.B) { for _, test := range tests { b.Run(fmt.Sprintf("n%d", len(test)), func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { HashString(test) } }) @@ -149,9 +148,7 @@ func BenchmarkHashMap(b *testing.B) { m[fmt.Sprintf("key%d", i)] = i } - b.ResetTimer() - - for i := 0; i < b.N; i++ { + for b.Loop() { HashString(m) } } diff --git a/common/hreflect/convert_test.go b/common/hreflect/convert_test.go index a130c4f1f..c64526ef6 100644 --- a/common/hreflect/convert_test.go +++ b/common/hreflect/convert_test.go @@ -278,7 +278,7 @@ func TestConvertIfPossibleMisc(t *testing.T) { func BenchmarkToInt64(b *testing.B) { v := reflect.ValueOf(int(42)) - for i := 0; i < b.N; i++ { + for b.Loop() { ToInt64(v) } } diff --git a/common/hreflect/helpers_test.go b/common/hreflect/helpers_test.go index 6a6e7b26b..9527fbb7d 100644 --- a/common/hreflect/helpers_test.go +++ b/common/hreflect/helpers_test.go @@ -156,12 +156,12 @@ func BenchmarkIsContextType(b *testing.B) { b.Run("value", func(b *testing.B) { ctx := context.Background() ctxs := make([]reflect.Type, b.N) - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { ctxs[i] = reflect.TypeOf(context.WithValue(ctx, k("key"), i)) } b.ResetTimer() - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { if !IsContextType(ctxs[i]) { b.Fatal("not context") } @@ -170,7 +170,7 @@ func BenchmarkIsContextType(b *testing.B) { b.Run("background", func(b *testing.B) { var ctxt reflect.Type = reflect.TypeOf(context.Background()) - for i := 0; i < b.N; i++ { + for b.Loop() { if !IsContextType(ctxt) { b.Fatal("not context") } @@ -189,8 +189,7 @@ func BenchmarkIsTruthFulValue(b *testing.B) { nilPointer = reflect.ValueOf((*zeroStruct)(nil)) ) - b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { IsTruthfulValue(stringHugo) IsTruthfulValue(stringEmpty) IsTruthfulValue(zero) @@ -227,8 +226,7 @@ func BenchmarkGetMethodByNameForType(b *testing.B) { tp := reflect.TypeFor[*testStruct]() methods := []string{"Method1", "Method2", "Method3", "Method4", "Method5"} - b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { for _, method := range methods { _ = GetMethodByNameForType(tp, method) } @@ -239,8 +237,7 @@ func BenchmarkGetMethodByName(b *testing.B) { v := reflect.ValueOf(&testStruct{}) methods := []string{"Method1", "Method2", "Method3", "Method4", "Method5"} - b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { for _, method := range methods { _ = GetMethodByName(v, method) } diff --git a/common/hstore/scratch_test.go b/common/hstore/scratch_test.go index b7253ab2a..1f08d46a9 100644 --- a/common/hstore/scratch_test.go +++ b/common/hstore/scratch_test.go @@ -214,8 +214,8 @@ func TestScratchGetSortedMapValues(t *testing.T) { func BenchmarkScratchGet(b *testing.B) { scratch := NewScratch() scratch.Add("A", 1) - b.ResetTimer() - for i := 0; i < b.N; i++ { + + for b.Loop() { scratch.Get("A") } } diff --git a/common/hstrings/strings_test.go b/common/hstrings/strings_test.go index 8c485130e..205005785 100644 --- a/common/hstrings/strings_test.go +++ b/common/hstrings/strings_test.go @@ -75,7 +75,7 @@ func BenchmarkUniqueStrings(b *testing.B) { input := []string{"a", "b", "d", "e", "d", "h", "a", "i"} b.Run("Safe", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { result := UniqueStrings(input) if len(result) != 6 { b.Fatalf("invalid count: %d", len(result)) @@ -86,13 +86,13 @@ func BenchmarkUniqueStrings(b *testing.B) { b.Run("Reuse slice", func(b *testing.B) { b.StopTimer() inputs := make([][]string, b.N) - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { inputc := make([]string, len(input)) copy(inputc, input) inputs[i] = inputc } b.StartTimer() - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { inputc := inputs[i] result := UniqueStringsReuse(inputc) @@ -105,13 +105,13 @@ func BenchmarkUniqueStrings(b *testing.B) { b.Run("Reuse slice sorted", func(b *testing.B) { b.StopTimer() inputs := make([][]string, b.N) - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { inputc := make([]string, len(input)) copy(inputc, input) inputs[i] = inputc } b.StartTimer() - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { inputc := inputs[i] result := UniqueStringsSorted(inputc) @@ -123,13 +123,13 @@ func BenchmarkUniqueStrings(b *testing.B) { } func BenchmarkGetOrCompileRegexp(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { GetOrCompileRegexp(`\d+`) } } func BenchmarkCompileRegexp(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { regexp.MustCompile(`\d+`) } } diff --git a/common/hsync/oncemore_test.go b/common/hsync/oncemore_test.go index e0b60418b..67a6e04d1 100644 --- a/common/hsync/oncemore_test.go +++ b/common/hsync/oncemore_test.go @@ -67,7 +67,7 @@ func BenchmarkOnceMoreValue(b *testing.B) { return counter } - for range b.N { + for b.Loop() { omf := OnceMoreValue(f) for range 10 { omf.Value(context.Background()) diff --git a/common/htime/time_test.go b/common/htime/time_test.go index 78954887e..a84d1c3bb 100644 --- a/common/htime/time_test.go +++ b/common/htime/time_test.go @@ -112,7 +112,7 @@ func BenchmarkTimeFormatter(b *testing.B) { june06, _ := time.Parse("2006-Jan-02", "2018-Jun-06") b.Run("Native", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { got := june06.Format("Monday Jan 2 2006") if got != "Wednesday Jun 6 2018" { b.Fatalf("invalid format, got %q", got) @@ -123,7 +123,7 @@ func BenchmarkTimeFormatter(b *testing.B) { b.Run("Localized", func(b *testing.B) { f := NewTimeFormatter(translators.GetTranslator("nn")) b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { got := f.Format(june06, "Monday Jan 2 2006") if got != "onsdag juni 6 2018" { b.Fatalf("invalid format, got %q", got) @@ -134,7 +134,7 @@ func BenchmarkTimeFormatter(b *testing.B) { b.Run("Localized Custom", func(b *testing.B) { f := NewTimeFormatter(translators.GetTranslator("nn")) b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { got := f.Format(june06, ":date_medium") if got != "6. juni 2018" { b.Fatalf("invalid format, got %q", got) diff --git a/common/maps/cache_test.go b/common/maps/cache_test.go index 17e38ace8..32bff9572 100644 --- a/common/maps/cache_test.go +++ b/common/maps/cache_test.go @@ -24,7 +24,7 @@ func TestCacheSize(t *testing.T) { cache := NewCacheWithOptions[string, string](CacheOptions{Size: 10}) - for i := 0; i < 30; i++ { + for i := range 30 { cache.Set(string(rune('a'+i)), "value") } diff --git a/common/maps/orderedintset_test.go b/common/maps/orderedintset_test.go index 243d0d617..2aab63028 100644 --- a/common/maps/orderedintset_test.go +++ b/common/maps/orderedintset_test.go @@ -68,31 +68,31 @@ func BenchmarkOrderedIntSet(b *testing.B) { } b.Run("New", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { NewOrderedIntSet(1, 2, 3, 4, 5, 6, 7, 8) } }) b.Run("Has small", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { smallSet.Has(i % 32) } }) b.Run("Has medium", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { mediumSet.Has(i % 32) } }) b.Run("Next", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { mediumSet.Next(i % 32) } }) b.Run("ForEachKey small", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { smallSet.ForEachKey(func(key int) bool { return true }) @@ -100,7 +100,7 @@ func BenchmarkOrderedIntSet(b *testing.B) { }) b.Run("ForEachKey medium", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { mediumSet.ForEachKey(func(key int) bool { return true }) @@ -108,7 +108,7 @@ func BenchmarkOrderedIntSet(b *testing.B) { }) b.Run("ForEachKey large", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { largeSet.ForEachKey(func(key int) bool { return true }) diff --git a/common/para/para_test.go b/common/para/para_test.go index cf24a4e37..3d28a017d 100644 --- a/common/para/para_test.go +++ b/common/para/para_test.go @@ -52,7 +52,6 @@ func TestPara(t *testing.T) { var result []int var mu sync.Mutex for i := range n { - i := i r.Run(func() error { mu.Lock() defer mu.Unlock() diff --git a/common/paths/path.go b/common/paths/path.go index de91d6a2f..e9b9108f5 100644 --- a/common/paths/path.go +++ b/common/paths/path.go @@ -115,8 +115,8 @@ func ReplaceExtension(path string, newExt string) string { func makePathRelative(inPath string, possibleDirectories ...string) (string, error) { for _, currentPath := range possibleDirectories { - if strings.HasPrefix(inPath, currentPath) { - return strings.TrimPrefix(inPath, currentPath), nil + if after, ok := strings.CutPrefix(inPath, currentPath); ok { + return after, nil } } return inPath, errors.New("can't extract relative path, unknown prefix") diff --git a/common/paths/path_test.go b/common/paths/path_test.go index 0e0dfc2e2..ebfd5acd7 100644 --- a/common/paths/path_test.go +++ b/common/paths/path_test.go @@ -225,7 +225,7 @@ func BenchmarkSanitize(b *testing.B) { // This should not allocate any memory. b.Run("All allowed", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { got := Sanitize(allAlowedPath) if got != allAlowedPath { b.Fatal(got) @@ -235,7 +235,7 @@ func BenchmarkSanitize(b *testing.B) { // This will allocate some memory. b.Run("Spaces", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { got := Sanitize(spacePath) if got != "foo-bar" { b.Fatal(got) @@ -320,7 +320,7 @@ func BenchmarkAddLeadingSlash(b *testing.B) { // This should not allocate any memory. b.Run("With leading slash", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { got := AddLeadingSlash(withLeadingSlash) if got != withLeadingSlash { b.Fatal(got) @@ -330,7 +330,7 @@ func BenchmarkAddLeadingSlash(b *testing.B) { // This will allocate some memory. b.Run("Without leading slash", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { got := AddLeadingSlash(noLeadingSlash) if got != "/a/b/c" { b.Fatal(got) @@ -339,7 +339,7 @@ func BenchmarkAddLeadingSlash(b *testing.B) { }) b.Run("Blank string", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { got := AddLeadingSlash("") if got != "/" { b.Fatal(got) diff --git a/common/paths/pathparser_test.go b/common/paths/pathparser_test.go index d7286d903..843b286c2 100644 --- a/common/paths/pathparser_test.go +++ b/common/paths/pathparser_test.go @@ -637,7 +637,7 @@ func TestHasExt(t *testing.T) { func BenchmarkParseIdentity(b *testing.B) { parser := newTestParser() - for i := 0; i < b.N; i++ { + for b.Loop() { parser.ParseIdentity(files.ComponentFolderAssets, "/a/b.css") } } @@ -656,7 +656,7 @@ func TestSitesMatrixFromPath(t *testing.T) { func BenchmarkSitesMatrixFromPath(b *testing.B) { parser := newTestParser() p := parser.Parse(files.ComponentFolderContent, "/a/b/c.fr.md") - for i := 0; i < b.N; i++ { + for b.Loop() { parser.SitesMatrixFromPath(p) } } diff --git a/common/predicate/predicate_test.go b/common/predicate/predicate_test.go index 5a9c8365b..7cfc11d11 100644 --- a/common/predicate/predicate_test.go +++ b/common/predicate/predicate_test.go @@ -150,7 +150,7 @@ func BenchmarkPredicate(b *testing.B) { b.Run("and or no match", func(b *testing.B) { var p predicate.PR[int] = intP1 p = p.And(intP2).Or(intP3) - for i := 0; i < b.N; i++ { + for b.Loop() { _ = p(3).OK() } }) @@ -158,7 +158,7 @@ func BenchmarkPredicate(b *testing.B) { b.Run("and and no match", func(b *testing.B) { var p predicate.PR[int] = intP1 p = p.And(intP2) - for range b.N { + for b.Loop() { _ = p(3).OK() } }) @@ -166,7 +166,7 @@ func BenchmarkPredicate(b *testing.B) { b.Run("and and match", func(b *testing.B) { var p predicate.PR[int] = intP1 p = p.And(intP2) - for range b.N { + for b.Loop() { _ = p(10).OK() } }) @@ -174,7 +174,7 @@ func BenchmarkPredicate(b *testing.B) { b.Run("or or match", func(b *testing.B) { var p predicate.PR[int] = intP1 p = p.Or(intP2).Or(intP3) - for range b.N { + for b.Loop() { _ = p(2).OK() } }) diff --git a/common/text/transform_test.go b/common/text/transform_test.go index 74bb37783..e5ed3567f 100644 --- a/common/text/transform_test.go +++ b/common/text/transform_test.go @@ -65,7 +65,7 @@ func BenchmarkVisitLinesAfter(b *testing.B) { line 3` - for i := 0; i < b.N; i++ { + for b.Loop() { VisitLinesAfter(lines, func(s string) { }) } diff --git a/compare/compare_strings_test.go b/compare/compare_strings_test.go index 1a5bb0b1a..505eaa7a3 100644 --- a/compare/compare_strings_test.go +++ b/compare/compare_strings_test.go @@ -67,12 +67,12 @@ func BenchmarkStringSort(b *testing.B) { prototype := []string{"b", "Bz", "zz", "ba", "αβδ αβδ αβδ", "A", "Ba", "ba", "nnnnasdfnnn", "AAgæåz", "αβδC"} b.Run("LessStrings", func(b *testing.B) { ss := make([][]string, b.N) - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { ss[i] = make([]string, len(prototype)) copy(ss[i], prototype) } b.ResetTimer() - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { sss := ss[i] sort.Slice(sss, func(i, j int) bool { return LessStrings(sss[i], sss[j]) diff --git a/config/allconfig/load.go b/config/allconfig/load.go index 4527a4554..ec6b71e05 100644 --- a/config/allconfig/load.go +++ b/config/allconfig/load.go @@ -220,8 +220,8 @@ func (l configLoader) applyOsEnvOverrides(environ []string) error { var hugoEnv []types.KeyValueStr for _, v := range environ { key, val := config.SplitEnvVar(v) - if strings.HasPrefix(key, hugoEnvPrefix) { - delimiterAndKey := strings.TrimPrefix(key, hugoEnvPrefix) + if after, ok := strings.CutPrefix(key, hugoEnvPrefix); ok { + delimiterAndKey := after if len(delimiterAndKey) < 2 { continue } diff --git a/config/allconfig/load_test.go b/config/allconfig/load_test.go index 3c16e71e9..10a88d7b7 100644 --- a/config/allconfig/load_test.go +++ b/config/allconfig/load_test.go @@ -58,7 +58,7 @@ weight = 4 Filename: configFilename, } - for i := 0; i < b.N; i++ { + for b.Loop() { _, err := LoadConfig(d) if err != nil { b.Fatal(err) diff --git a/config/defaultConfigProvider_test.go b/config/defaultConfigProvider_test.go index 204861216..a21d573ed 100644 --- a/config/defaultConfigProvider_test.go +++ b/config/defaultConfigProvider_test.go @@ -334,7 +334,6 @@ func TestDefaultConfigProvider(t *testing.T) { } for i := range 20 { - i := i r.Run(func() error { const v = 42 k := fmt.Sprintf("k%d", i) @@ -478,7 +477,7 @@ func BenchmarkDefaultConfigProvider(b *testing.B) { b.Run("Custom", func(b *testing.B) { cfg := New() - for i := 0; i < b.N; i++ { + for b.Loop() { runMethods(b, cfg) } }) diff --git a/create/content_test.go b/create/content_test.go index 22629fdbc..deafaed09 100644 --- a/create/content_test.go +++ b/create/content_test.go @@ -74,7 +74,6 @@ func TestNewContentFromFile(t *testing.T) { c := qt.New(t) for i, cas := range cases { - cas := cas c.Run(cas.name, func(c *qt.C) { c.Parallel() diff --git a/helpers/content_test.go b/helpers/content_test.go index dd7c5a4c5..e2c755a7b 100644 --- a/helpers/content_test.go +++ b/helpers/content_test.go @@ -54,8 +54,8 @@ func TestTrimShortHTML(t *testing.T) { func BenchmarkTrimShortHTML(b *testing.B) { c := newTestContentSpec(nil) - b.ResetTimer() - for i := 0; i < b.N; i++ { + + for b.Loop() { c.TrimShortHTML([]byte("
Simple paragraph
"), "markdown") } } @@ -134,8 +134,8 @@ func TestTotalWords(t *testing.T) { } func BenchmarkTotalWords(b *testing.B) { - b.ResetTimer() - for i := 0; i < b.N; i++ { + + for b.Loop() { wordCount := helpers.TotalWords(totalWordsBenchmarkString) if wordCount != 400 { b.Fatal("Wordcount error") diff --git a/helpers/general_test.go b/helpers/general_test.go index f7bcb6642..53c1925d4 100644 --- a/helpers/general_test.go +++ b/helpers/general_test.go @@ -214,8 +214,8 @@ func TestGetTitleFunc(t *testing.T) { } func BenchmarkReaderContains(b *testing.B) { - b.ResetTimer() - for i := 0; i < b.N; i++ { + + for b.Loop() { for i, this := range containsBenchTestData { result := helpers.ReaderContains(strings.NewReader(this.v1), this.v2) if result != this.expect { diff --git a/helpers/path.go b/helpers/path.go index aee617282..f8f1e2ece 100644 --- a/helpers/path.go +++ b/helpers/path.go @@ -73,8 +73,8 @@ func MakeTitle(inpath string) string { // MakeTitleInPath converts the path given to a suitable title, trimming whitespace func MakePathRelative(inPath string, possibleDirectories ...string) (string, error) { for _, currentPath := range possibleDirectories { - if strings.HasPrefix(inPath, currentPath) { - return strings.TrimPrefix(inPath, currentPath), nil + if after, ok := strings.CutPrefix(inPath, currentPath); ok { + return after, nil } } return inPath, errors.New("can't extract relative path, unknown prefix") @@ -226,8 +226,8 @@ func ExtractRootPaths(paths []string) []string { r := make([]string, len(paths)) for i, p := range paths { root := filepath.ToSlash(p) - sections := strings.Split(root, "/") - for _, section := range sections { + sections := strings.SplitSeq(root, "/") + for section := range sections { if section != "" { root = section break diff --git a/helpers/url_test.go b/helpers/url_test.go index 7f625035c..309dee18a 100644 --- a/helpers/url_test.go +++ b/helpers/url_test.go @@ -259,8 +259,8 @@ func BenchmarkRelURL(b *testing.B) { v := config.New() v.Set("baseURL", "https://base/") p := newTestPathSpecFromCfgAndLang(v, "") - b.ResetTimer() - for i := 0; i < b.N; i++ { + + for b.Loop() { _ = p.RelURL("https://base/foo/bar", false) } } @@ -271,12 +271,12 @@ func BenchmarkAbsURL(b *testing.B) { p := newTestPathSpecFromCfgAndLang(v, "") b.ResetTimer() b.Run("relurl", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { _ = p.AbsURL("foo/bar", false) } }) b.Run("absurl", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { _ = p.AbsURL("https://base/foo/bar", false) } }) diff --git a/hugofs/hashing_fs_test.go b/hugofs/hashing_fs_test.go index 74781ba8d..0d436a87e 100644 --- a/hugofs/hashing_fs_test.go +++ b/hugofs/hashing_fs_test.go @@ -59,9 +59,7 @@ func BenchmarkHashingFs(b *testing.B) { ofs := NewHashingFs(fs, observer) content := []byte(strings.Repeat("lorem ipsum ", 1000)) - b.ResetTimer() - - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { f, err := ofs.Create(fmt.Sprintf("file%d", i)) if err != nil { b.Fatal(err) diff --git a/hugofs/hglob/glob_test.go b/hugofs/hglob/glob_test.go index e69e0e622..72b675242 100644 --- a/hugofs/hglob/glob_test.go +++ b/hugofs/hglob/glob_test.go @@ -81,7 +81,7 @@ func BenchmarkGetGlob(b *testing.B) { if err != nil { b.Fatal(err) } - for i := 0; i < b.N; i++ { + for b.Loop() { _ = g.Match(search) } }) @@ -92,7 +92,7 @@ func BenchmarkGetGlob(b *testing.B) { runBench("Filenames cache, mixed case searches", defaultGlobCache, "abCDe") b.Run("GetGlob", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { _, err := GetGlob("**/foo") if err != nil { b.Fatal(err) diff --git a/hugofs/walk_test.go b/hugofs/walk_test.go index d8dc0d9b0..9d37cb07f 100644 --- a/hugofs/walk_test.go +++ b/hugofs/walk_test.go @@ -182,8 +182,7 @@ func BenchmarkWalk(b *testing.B) { return nil } - b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { w := NewWalkway(WalkwayConfig{Fs: fs, Root: "root", WalkFn: walkFn}) if err := w.Walk(); err != nil { diff --git a/hugolib/cascade_test.go b/hugolib/cascade_test.go index e7a4f7917..659006a2c 100644 --- a/hugolib/cascade_test.go +++ b/hugolib/cascade_test.go @@ -36,12 +36,12 @@ func BenchmarkCascade(b *testing.B) { c := qt.New(b) b.StopTimer() builders := make([]*sitesBuilder, b.N) - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { builders[i] = newCascadeTestBuilder(b, langs) } b.StartTimer() - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { builder := builders[i] err := builder.BuildE(BuildCfg{}) c.Assert(err, qt.IsNil) @@ -83,7 +83,7 @@ kind = '{section,term}' b.ResetTimer() - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { builders[i].Build() } }) diff --git a/hugolib/config_test.go b/hugolib/config_test.go index 5ee13ca30..c7c093594 100644 --- a/hugolib/config_test.go +++ b/hugolib/config_test.go @@ -721,7 +721,6 @@ themeconfigdirparam: {{ site.Params.themeconfigdirparam }} ` for _, configName := range []string{"hugo.toml", "config.toml"} { - configName := configName t.Run(configName, func(t *testing.T) { t.Parallel() diff --git a/hugolib/content_map_test.go b/hugolib/content_map_test.go index 971be7b55..6882711fe 100644 --- a/hugolib/content_map_test.go +++ b/hugolib/content_map_test.go @@ -484,7 +484,6 @@ Path: {{ .Path }}|{{.Kind }} ` for _, format := range []string{"toml", "yaml", "json"} { - format := format t.Run(format, func(t *testing.T) { t.Parallel() diff --git a/hugolib/content_render_hooks_test.go b/hugolib/content_render_hooks_test.go index c4e15a5c6..31ce545b5 100644 --- a/hugolib/content_render_hooks_test.go +++ b/hugolib/content_render_hooks_test.go @@ -332,7 +332,6 @@ Image:  ` for _, enabled := range []bool{true, false} { - enabled := enabled t.Run(fmt.Sprint(enabled), func(t *testing.T) { t.Parallel() b := Test(t, strings.ReplaceAll(files, "ENABLE", fmt.Sprint(enabled))) diff --git a/hugolib/doctree/nodeshiftree_test.go b/hugolib/doctree/nodeshiftree_test.go index 946e6d187..74ce26043 100644 --- a/hugolib/doctree/nodeshiftree_test.go +++ b/hugolib/doctree/nodeshiftree_test.go @@ -195,7 +195,6 @@ func TestTreePara(t *testing.T) { ) for i := range 8 { - i := i r.Run(func() error { a := &testValue{ID: "/a"} lock := tree.Lock(true) @@ -302,7 +301,7 @@ type testValue struct { func BenchmarkTreeInsert(b *testing.B) { runBench := func(b *testing.B, numElements int) { - for i := 0; i < b.N; i++ { + for b.Loop() { tree := doctree.New( doctree.Config[*testValue]{ Shifter: &testShifter{}, @@ -360,7 +359,7 @@ func BenchmarkWalk(b *testing.B) { b.Run(fmt.Sprintf("Walk one dimension %d", numElements), func(b *testing.B) { tree := createTree() b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { w := &doctree.NodeShiftTreeWalker[*testValue]{ Tree: tree, Handle: handle, @@ -374,7 +373,7 @@ func BenchmarkWalk(b *testing.B) { b.Run(fmt.Sprintf("Walk all dimensions %d", numElements), func(b *testing.B) { base := createTree() b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { for d1 := range 1 { for d2 := range 2 { tree := base.Shape(sitesmatrix.Vector{d1, d2, 0}) diff --git a/hugolib/doctree/treeshifttree_test.go b/hugolib/doctree/treeshifttree_test.go index b0ae79633..f5b5802cd 100644 --- a/hugolib/doctree/treeshifttree_test.go +++ b/hugolib/doctree/treeshifttree_test.go @@ -32,7 +32,7 @@ func BenchmarkTreeShiftTreeSlice(b *testing.B) { v := sitesmatrix.Vector{10, 10, 10} t := doctree.NewTreeShiftTree[string](v) b.Run("New", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { for l1 := 0; l1 < v[0]; l1++ { for l2 := 0; l2 < v[1]; l2++ { for l3 := 0; l3 < v[2]; l3++ { @@ -43,7 +43,7 @@ func BenchmarkTreeShiftTreeSlice(b *testing.B) { } }) b.Run("Shape", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { for l1 := 0; l1 < v[0]; l1++ { for l2 := 0; l2 < v[1]; l2++ { for l3 := 0; l3 < v[2]; l3++ { diff --git a/hugolib/filesystems/basefs.go b/hugolib/filesystems/basefs.go index dd3d97e6c..9fa561906 100644 --- a/hugolib/filesystems/basefs.go +++ b/hugolib/filesystems/basefs.go @@ -183,8 +183,8 @@ func (b *BaseFs) AbsProjectContentDir(filename string) (string, string, error) { } else { contentDir := strings.TrimPrefix(strings.TrimPrefix(meta.Filename, meta.BaseDir), filePathSeparator) + filePathSeparator - if strings.HasPrefix(filename, contentDir) { - relFilename := strings.TrimPrefix(filename, contentDir) + if after, ok := strings.CutPrefix(filename, contentDir); ok { + relFilename := after absFilename := filepath.Join(meta.Filename, relFilename) return relFilename, absFilename, nil } diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go index 5621cd6e6..b1ac8fb25 100644 --- a/hugolib/hugo_sites.go +++ b/hugolib/hugo_sites.go @@ -674,9 +674,9 @@ func (h *HugoSites) handleDataFile(r *source.File) error { // Crawl in data tree to insert data current = h.data dataPath := r.FileInfo().Meta().PathInfo.Unnormalized().Dir()[1:] - keyParts := strings.Split(dataPath, "/") + keyParts := strings.SplitSeq(dataPath, "/") - for _, key := range keyParts { + for key := range keyParts { if key != "" { if _, ok := current[key]; !ok { current[key] = make(map[string]any) diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go index 3cd30c41d..b0157bb59 100644 --- a/hugolib/hugo_sites_build.go +++ b/hugolib/hugo_sites_build.go @@ -346,7 +346,6 @@ func (h *HugoSites) assemble(ctx context.Context, l logg.LevelLogger, bcfg *Buil g, _ := h.workersSite.Start(ctx) for _, s := range assemblers { - s := s g.Run(func() error { return s.assemblePagesStep1() }) @@ -751,7 +750,6 @@ func (h *HugoSites) postProcess(l logg.LevelLogger) error { filenames := h.Deps.BuildState.GetFilenamesWithPostPrefix() for _, filename := range filenames { - filename := filename g.Run(func() error { return handleFile(filename) }) diff --git a/hugolib/hugo_smoke_test.go b/hugolib/hugo_smoke_test.go index c6508bc04..9b4079dc9 100644 --- a/hugolib/hugo_smoke_test.go +++ b/hugolib/hugo_smoke_test.go @@ -330,7 +330,7 @@ Single: {{ .Title }}|{{ .RelPermalink}}|{{ range .OutputFormats }}{{ .Name }}: { ` - for i := 0; i < 2; i++ { + for range 2 { b := Test(t, files) b.AssertFileContent("public/index.html", `List: |/|html: /|rss: /index.xml|$`) b.AssertFileContent("public/index.xml", `List xml: |/|html: /|rss: /index.xml|$`) @@ -749,8 +749,7 @@ func BenchmarkBaseline(b *testing.B) { builders[i] = NewIntegrationTestBuilder(cfg) } - b.ResetTimer() - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { builders[i].Build() } } diff --git a/hugolib/integrationtest_builder.go b/hugolib/integrationtest_builder.go index 210a53d32..d1d787797 100644 --- a/hugolib/integrationtest_builder.go +++ b/hugolib/integrationtest_builder.go @@ -408,8 +408,8 @@ func (s *IntegrationTestBuilder) AssertFileContent(filename string, matches ...s for _, m := range matches { cm := qt.Commentf("File: %s Expect: %s Got: %s", filename, m, content) - lines := strings.Split(m, "\n") - for _, match := range lines { + lines := strings.SplitSeq(m, "\n") + for match := range lines { match = strings.TrimSpace(match) if match == "" || strings.HasPrefix(match, "#") { continue @@ -463,8 +463,8 @@ func (s *IntegrationTestBuilder) AssertFs(fs afero.Fs, matches ...string) { content := strings.TrimSpace((strings.Join(printFsLines, "\n"))) for _, m := range matches { cm := qt.Commentf("Match: %q\nIn:\n%s", m, content) - lines := strings.Split(m, "\n") - for _, match := range lines { + lines := strings.SplitSeq(m, "\n") + for match := range lines { match = strings.TrimSpace(match) var negate bool if strings.HasPrefix(match, hglob.NegationPrefix) { diff --git a/hugolib/page_permalink_test.go b/hugolib/page_permalink_test.go index d8fd99d79..03fe62cec 100644 --- a/hugolib/page_permalink_test.go +++ b/hugolib/page_permalink_test.go @@ -64,7 +64,6 @@ func TestPermalink(t *testing.T) { } for i, test := range tests { - i := i test := test t.Run(fmt.Sprintf("%s-%d", test.file, i), func(t *testing.T) { t.Parallel() diff --git a/hugolib/page_test.go b/hugolib/page_test.go index e8f8ced02..b8d56f758 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -1068,7 +1068,6 @@ func TestPageWithDate(t *testing.T) { func TestPageWithFrontMatterConfig(t *testing.T) { for _, dateHandler := range []string{":filename", ":fileModTime"} { - dateHandler := dateHandler t.Run(fmt.Sprintf("dateHandler=%q", dateHandler), func(t *testing.T) { t.Parallel() c := qt.New(t) diff --git a/hugolib/pagecollections_test.go b/hugolib/pagecollections_test.go index 10c973b7e..0ea757b1c 100644 --- a/hugolib/pagecollections_test.go +++ b/hugolib/pagecollections_test.go @@ -57,12 +57,11 @@ func BenchmarkGetPage(b *testing.B) { pagePaths := make([]string, b.N) - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { pagePaths[i] = fmt.Sprintf("sect%d", r.Intn(10)) } - b.ResetTimer() - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { home, _ := s.getPage(nil, "/") if home == nil { b.Fatal("Home is nil") @@ -121,12 +120,12 @@ func BenchmarkGetPageRegular(b *testing.B) { pagePaths := make([]string, b.N) - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { pagePaths[i] = path.Join(fmt.Sprintf("/sect%d", r.Intn(10)), fmt.Sprintf("page%d.md", r.Intn(100))) } b.ResetTimer() - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { page, _ := s.getPage(nil, pagePaths[i]) c.Assert(page, qt.Not(qt.IsNil)) } @@ -140,13 +139,13 @@ func BenchmarkGetPageRegular(b *testing.B) { pagePaths := make([]string, b.N) pages := make([]page.Page, b.N) - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { pagePaths[i] = fmt.Sprintf("page%d.md", r.Intn(100)) pages[i] = allPages[r.Intn(len(allPages)/3)] } b.ResetTimer() - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { page, _ := s.getPage(pages[i], pagePaths[i]) c.Assert(page, qt.Not(qt.IsNil)) } diff --git a/hugolib/pages_language_merge_test.go b/hugolib/pages_language_merge_test.go index ba1ed83de..62f040739 100644 --- a/hugolib/pages_language_merge_test.go +++ b/hugolib/pages_language_merge_test.go @@ -187,7 +187,7 @@ func BenchmarkMergeByLanguage(b *testing.B) { enSite := h.Sites[0] nnSite := h.Sites[2] - for i := 0; i < b.N; i++ { + for b.Loop() { merged := nnSite.RegularPages().MergeByLanguage(enSite.RegularPages()) if len(merged) != count { b.Fatal("Count mismatch") diff --git a/hugolib/pages_test.go b/hugolib/pages_test.go index 30e9e59d2..cbcaad48d 100644 --- a/hugolib/pages_test.go +++ b/hugolib/pages_test.go @@ -77,7 +77,7 @@ func BenchmarkPagesPrevNext(b *testing.B) { pages = variant.preparePages(pages) } b.StartTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { p := pages[rand.Intn(len(pages))] variant.run(p, pages) } @@ -109,7 +109,7 @@ func BenchmarkPagePageCollections(b *testing.B) { } } b.StartTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { p := pages[rand.Intn(len(pages))] variant.run(p) } diff --git a/hugolib/pagesfromdata/pagesfromgotmpl_test.go b/hugolib/pagesfromdata/pagesfromgotmpl_test.go index c60b56dbf..59cfa7abe 100644 --- a/hugolib/pagesfromdata/pagesfromgotmpl_test.go +++ b/hugolib/pagesfromdata/pagesfromgotmpl_test.go @@ -26,7 +26,7 @@ func BenchmarkHash(b *testing.B) { bs := BuildState{} - for i := 0; i < b.N; i++ { + for b.Loop() { bs.hash(m) } } diff --git a/hugolib/rebuild_test.go b/hugolib/rebuild_test.go index 657ed5609..53a3bef6c 100644 --- a/hugolib/rebuild_test.go +++ b/hugolib/rebuild_test.go @@ -102,7 +102,7 @@ My Other Text: {{ $r.Content }}|{{ $r.Permalink }}| func TestRebuildEditLeafBundleHeaderOnly(t *testing.T) { t.Parallel() - for i := 0; i < 3; i++ { + for range 3 { b := TestRunning(t, rebuildFilesSimple) b.AssertFileContent("public/mysection/mysectionbundle/index.html", "My Section Bundle Content Content.") @@ -1797,8 +1797,7 @@ func BenchmarkRebuildContentFileChange(b *testing.B) { builders[i].Build() } - b.ResetTimer() - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { bb := builders[i] bb.EditFileReplaceFunc("content/mysect/p123/index.md", func(s string) string { return s + "... Edited" diff --git a/hugolib/resource_chain_test.go b/hugolib/resource_chain_test.go index 36e50ae3b..a8bd2d56f 100644 --- a/hugolib/resource_chain_test.go +++ b/hugolib/resource_chain_test.go @@ -198,7 +198,7 @@ relPermalink": "/hello.min.a2d1cb24f24b322a7dad520414c523e9.html" } func BenchmarkResourceChainPostProcess(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { b.StopTimer() s := newTestSitesBuilder(b) for i := range 300 { @@ -579,7 +579,6 @@ XML: {{ $xml.body }} } for _, test := range tests { - test := test t.Run(test.name, func(t *testing.T) { if !test.shouldRun() { t.Skip() diff --git a/hugolib/segments/segments_test.go b/hugolib/segments/segments_test.go index d98df281c..f07dea969 100644 --- a/hugolib/segments/segments_test.go +++ b/hugolib/segments/segments_test.go @@ -144,8 +144,7 @@ func BenchmarkSegmentsMatch(b *testing.B) { match := compileSegments(c, fields...) - b.ResetTimer() - for range b.N { + for b.Loop() { match(SegmentQuery{Site: no, Output: "rss"}) } } diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go index 20fe2bc9d..ec6e25cd6 100644 --- a/hugolib/shortcode.go +++ b/hugolib/shortcode.go @@ -85,8 +85,8 @@ func (scp *ShortcodeWithPage) InnerDeindent() template.HTML { scp.innerDeindentInit.Do(func() { b := bp.GetBuffer() text.VisitLinesAfter(string(scp.Inner), func(s string) { - if strings.HasPrefix(s, scp.indentation) { - b.WriteString(strings.TrimPrefix(s, scp.indentation)) + if after, ok := strings.CutPrefix(s, scp.indentation); ok { + b.WriteString(after) } else { b.WriteString(s) } diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go index 90fda6593..cf0a77f18 100644 --- a/hugolib/shortcode_test.go +++ b/hugolib/shortcode_test.go @@ -101,8 +101,6 @@ title: "Shortcodes Galore!" {"inline", `{{< my.inline >}}Hi{{< /my.inline >}}`, regexpCheck("my.inline;inline:true;closing:true;inner:{Hi};")}, } { - test := test - t.Run(test.name, func(t *testing.T) { t.Parallel() c := qt.New(t) @@ -266,7 +264,7 @@ func BenchmarkReplaceShortcodeTokens(b *testing.B) { cnt := 0 in := make([]input, b.N*len(data)) - for i := 0; i < b.N; i++ { + for b.Loop() { for _, this := range data { replacements := make(map[string]shortcodeRenderer) for k, v := range this.replacements { @@ -280,10 +278,9 @@ func BenchmarkReplaceShortcodeTokens(b *testing.B) { } } - b.ResetTimer() cnt = 0 ctx := context.Background() - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { for j := range data { currIn := in[cnt] cnt++ @@ -345,9 +342,7 @@ title: "Markdown Shortcode" builders[i] = NewIntegrationTestBuilder(cfg) } - b.ResetTimer() - - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { builders[i].Build() } } @@ -644,7 +639,6 @@ String: {{ . | safeHTML }} func TestInlineShortcodes(t *testing.T) { for _, enableInlineShortcodes := range []bool{true, false} { - enableInlineShortcodes := enableInlineShortcodes t.Run(fmt.Sprintf("enableInlineShortcodes=%t", enableInlineShortcodes), func(t *testing.T) { t.Parallel() diff --git a/hugolib/site.go b/hugolib/site.go index be75f5c7b..ce0331200 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -363,7 +363,7 @@ func NewHugoSites(cfg deps.DepsCfg) (*HugoSites, error) { sitesVersionsRoles := make([][][]*Site, len(sites)) for i := 0; i < len(sites); i++ { sitesVersionsRoles[i] = make([][]*Site, len(versionsSorted)) - for j := 0; j < len(versionsSorted); j++ { + for j := range versionsSorted { sitesVersionsRoles[i][j] = make([]*Site, len(rolesSorted)) } } diff --git a/hugolib/site_benchmark_new_test.go b/hugolib/site_benchmark_new_test.go index 023d8e4d5..75f53cbfd 100644 --- a/hugolib/site_benchmark_new_test.go +++ b/hugolib/site_benchmark_new_test.go @@ -504,7 +504,7 @@ func BenchmarkSiteNew(b *testing.B) { } b.Run(name, func(b *testing.B) { sites := make([]*sitesBuilder, b.N) - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { sites[i] = bm.create(b) if edit { sites[i].Running() @@ -512,7 +512,7 @@ func BenchmarkSiteNew(b *testing.B) { } b.ResetTimer() - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { if edit { b.StopTimer() } diff --git a/hugolib/site_output_test.go b/hugolib/site_output_test.go index caec4c700..14997f688 100644 --- a/hugolib/site_output_test.go +++ b/hugolib/site_output_test.go @@ -30,7 +30,6 @@ import ( func TestSiteWithPageOutputs(t *testing.T) { for _, outputs := range [][]string{{"html", "json", "calendar"}, {"json"}} { - outputs := outputs t.Run(fmt.Sprintf("%v", outputs), func(t *testing.T) { t.Parallel() doTestSiteWithPageOutputs(t, outputs) diff --git a/hugolib/site_sections_test.go b/hugolib/site_sections_test.go index 357d3e77d..a64c653b0 100644 --- a/hugolib/site_sections_test.go +++ b/hugolib/site_sections_test.go @@ -286,7 +286,6 @@ PAG|{{ .Title }}|{{ $sect.InSection . }} home := s.getPageOldVersion(kinds.KindHome) for _, test := range tests { - test := test tt.Run(fmt.Sprintf("sections %s", test.sections), func(c *qt.C) { c.Parallel() sections := strings.Split(test.sections, ",") diff --git a/hugolib/sitesmatrix/dimensions_test.go b/hugolib/sitesmatrix/dimensions_test.go index 6d138a9d4..83cb5aa4c 100644 --- a/hugolib/sitesmatrix/dimensions_test.go +++ b/hugolib/sitesmatrix/dimensions_test.go @@ -49,7 +49,7 @@ func BenchmarkCompare(b *testing.B) { b.Run("Equal", func(b *testing.B) { v1 := Vector{1, 2, 3} v2 := Vector{1, 2, 3} - for range b.N { + for b.Loop() { v1.Compare(v2) } }) @@ -57,7 +57,7 @@ func BenchmarkCompare(b *testing.B) { b.Run("First different", func(b *testing.B) { v1 := Vector{1, 2, 3} v2 := Vector{2, 2, 3} - for range b.N { + for b.Loop() { v1.Compare(v2) } }) @@ -65,7 +65,7 @@ func BenchmarkCompare(b *testing.B) { b.Run("Last different", func(b *testing.B) { v1 := Vector{1, 2, 3} v2 := Vector{1, 2, 4} - for range b.N { + for b.Loop() { v1.Compare(v2) } }) diff --git a/hugolib/sitesmatrix/sitematrix_integration_test.go b/hugolib/sitesmatrix/sitematrix_integration_test.go index 9408a701d..3e93e8f96 100644 --- a/hugolib/sitesmatrix/sitematrix_integration_test.go +++ b/hugolib/sitesmatrix/sitematrix_integration_test.go @@ -1125,11 +1125,11 @@ func BenchmarkSitesMatrixContent(b *testing.B) { for _, multipleDimensions := range []bool{false, true} { b.Run(fmt.Sprintf("n%d/md%t", numPages, multipleDimensions), func(b *testing.B) { builders := make([]*hugolib.IntegrationTestBuilder, b.N) - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { builders[i] = newSitesMatrixContentBenchmarkBuilder(b, numPages, true, true) } b.ResetTimer() - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { builders[i].Build() } }) diff --git a/hugolib/sitesmatrix/vectorstores_test.go b/hugolib/sitesmatrix/vectorstores_test.go index 2f41a3bc9..1365c9055 100644 --- a/hugolib/sitesmatrix/vectorstores_test.go +++ b/hugolib/sitesmatrix/vectorstores_test.go @@ -339,37 +339,37 @@ func BenchmarkIntSetsComplement(b *testing.B) { b.ResetTimer() b.Run("sub set", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { _ = sets2.Complement(sets1) } }) b.Run("super set", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { _ = sets1.Complement(sets2) } }) b.Run("self", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { _ = sets1.Complement(sets1) } }) b.Run("self multiple", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { _ = sets1.Complement(sets1, sets1, sets1, sets1, sets1, sets1, sets1) } }) b.Run("same", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { _ = sets1.Complement(sets1Copy) } }) b.Run("one overlapping language", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { _ = setsLanguage1.Complement(sets1) } }) @@ -399,7 +399,7 @@ func BenchmarkSets(b *testing.B) { b.ResetTimer() b.Run("Build", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { _ = sitesmatrix.NewIntSetsBuilder(testDims).WithSets( maps.NewOrderedIntSet(1, 2), maps.NewOrderedIntSet(1, 2, 3), @@ -408,32 +408,32 @@ func BenchmarkSets(b *testing.B) { } }) b.Run("HasVector", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { _ = sets1.HasVector(v1) _ = sets1.HasVector(v2) } }) b.Run("HasAnyVector", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { _ = sets1.HasAnyVector(sets2) } }) b.Run("FirstVector", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { _ = sets1.VectorSample() } }) b.Run("LenVectors", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { _ = sets1.LenVectors() } }) b.Run("ForEachVector", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { allCount := 0 ok := sets1.ForEachVector(func(v sitesmatrix.Vector) bool { allCount++ @@ -452,7 +452,7 @@ func BenchmarkSets(b *testing.B) { }) b.Run("EqualsVector pointer equal", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { if !sets1.EqualsVector(sets1) { b.Fatal("Expected sets1 to equal itself") } @@ -460,7 +460,7 @@ func BenchmarkSets(b *testing.B) { }) b.Run("EqualsVector equal copy", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { if !sets1.EqualsVector(sets1Copy) { b.Fatal("Expected sets1 to equal its copy") } @@ -468,7 +468,7 @@ func BenchmarkSets(b *testing.B) { }) b.Run("EqualsVector different sets", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { if sets1.EqualsVector(sets2) { b.Fatal("Expected sets1 to not equal sets2") } @@ -476,7 +476,7 @@ func BenchmarkSets(b *testing.B) { }) b.Run("Distance", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { _ = sets1.VectorSample().Distance(v1) _ = sets1.VectorSample().Distance(v2) } diff --git a/hugolib/taxonomy_test.go b/hugolib/taxonomy_test.go index 272735367..4b3010859 100644 --- a/hugolib/taxonomy_test.go +++ b/hugolib/taxonomy_test.go @@ -877,7 +877,7 @@ GetTerms.tags: {{ range .GetTerms "tags" }}{{ .Title }}|{{ end }} for _, numPages := range []int{100, 1000, 10000, 20000} { b.Run(fmt.Sprintf("pages_%d", numPages), func(b *testing.B) { builders := createBuilders(b, numPages) - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { builders[i].Build() } }) diff --git a/hugolib/template_test.go b/hugolib/template_test.go index 31b18bdc4..56b9c3f9b 100644 --- a/hugolib/template_test.go +++ b/hugolib/template_test.go @@ -186,7 +186,6 @@ func TestTemplateLookupOrder(t *testing.T) { }, } { - this := this if this.name != "Variant 1" { continue } diff --git a/hugolib/testhelpers_test.go b/hugolib/testhelpers_test.go index 2007b658d..2fa3d5634 100644 --- a/hugolib/testhelpers_test.go +++ b/hugolib/testhelpers_test.go @@ -750,8 +750,8 @@ func (s *sitesBuilder) AssertFileContent(filename string, matches ...string) { s.T.Helper() content := s.FileContent(filename) for _, m := range matches { - lines := strings.Split(m, "\n") - for _, match := range lines { + lines := strings.SplitSeq(m, "\n") + for match := range lines { match = strings.TrimSpace(match) if match == "" { continue diff --git a/identity/finder_test.go b/identity/finder_test.go index 949a43713..85a5fd928 100644 --- a/identity/finder_test.go +++ b/identity/finder_test.go @@ -39,7 +39,7 @@ func BenchmarkFinder(b *testing.B) { f := identity.NewFinder(identity.FinderConfig{}) b.Run("Find one", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { r := f.Contains(b4, m1, -1) if r == 0 { b.Fatal("not found") @@ -48,7 +48,7 @@ func BenchmarkFinder(b *testing.B) { }) b.Run("Find none", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { r := f.Contains(b5, m1, -1) if r > 0 { b.Fatal("found") diff --git a/identity/identity_test.go b/identity/identity_test.go index dac92d86b..a14ab615d 100644 --- a/identity/identity_test.go +++ b/identity/identity_test.go @@ -33,7 +33,7 @@ func BenchmarkIdentityManager(b *testing.B) { } b.Run("identity.NewManager", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { m := identity.NewManager() if m == nil { b.Fatal("manager is nil") @@ -46,7 +46,7 @@ func BenchmarkIdentityManager(b *testing.B) { im := identity.NewManager() b.ResetTimer() - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { im.AddIdentity(ids[i]) } @@ -58,7 +58,7 @@ func BenchmarkIdentityManager(b *testing.B) { im := identity.NewManager() b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { im.AddIdentity(id) } @@ -67,33 +67,33 @@ func BenchmarkIdentityManager(b *testing.B) { b.Run("Nop StringIdentity const", func(b *testing.B) { const id = identity.StringIdentity("test") - for i := 0; i < b.N; i++ { + for b.Loop() { identity.NopManager.AddIdentity(id) } }) b.Run("Nop StringIdentity const other package", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { identity.NopManager.AddIdentity(identitytesting.TestIdentity) } }) b.Run("Nop StringIdentity var", func(b *testing.B) { id := identity.StringIdentity("test") - for i := 0; i < b.N; i++ { + for b.Loop() { identity.NopManager.AddIdentity(id) } }) b.Run("Nop pointer identity", func(b *testing.B) { id := &testIdentity{base: "a", name: "b"} - for i := 0; i < b.N; i++ { + for b.Loop() { identity.NopManager.AddIdentity(id) } }) b.Run("Nop Anonymous", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { identity.NopManager.AddIdentity(identity.Anonymous) } }) @@ -101,7 +101,7 @@ func BenchmarkIdentityManager(b *testing.B) { func BenchmarkIsNotDependent(b *testing.B) { runBench := func(b *testing.B, id1, id2 identity.Identity) { - for i := 0; i < b.N; i++ { + for b.Loop() { isNotDependent(id1, id2) } } diff --git a/internal/js/esbuild/resolve.go b/internal/js/esbuild/resolve.go index a2516dbd2..18ad8a40a 100644 --- a/internal/js/esbuild/resolve.go +++ b/internal/js/esbuild/resolve.go @@ -186,8 +186,8 @@ func createBuildPlugins(rs *resources.Spec, assetsResolver *fsResolver, depsMana isStdin := importer == stdinImporter var relDir string if !isStdin { - if strings.HasPrefix(importer, PrefixHugoVirtual) { - relDir = filepath.Dir(strings.TrimPrefix(importer, PrefixHugoVirtual)) + if after, ok := strings.CutPrefix(importer, PrefixHugoVirtual); ok { + relDir = filepath.Dir(after) } else { rel, found := fs.MakePathRelative(importer, true) diff --git a/internal/warpc/warpc.go b/internal/warpc/warpc.go index e21fefa8a..0d8d6a030 100644 --- a/internal/warpc/warpc.go +++ b/internal/warpc/warpc.go @@ -435,7 +435,6 @@ func newDispatcher[Q, R any](opts Options) (*dispatcherPool[Q, R], error) { run := func() error { g, ctx := errgroup.WithContext(ctx) for _, c := range inOuts { - c := c g.Go(func() error { var errBuff bytes.Buffer ctx := context.WithoutCancel(ctx) diff --git a/internal/warpc/warpc_test.go b/internal/warpc/warpc_test.go index 2ee4c3de5..d19334806 100644 --- a/internal/warpc/warpc_test.go +++ b/internal/warpc/warpc_test.go @@ -263,8 +263,7 @@ func BenchmarkExecuteKatex(b *testing.B) { input := katexInputTemplate - b.ResetTimer() - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { message := Message[KatexInput]{ Header: Header{ Version: currentVersion, @@ -293,7 +292,7 @@ func BenchmarkKatexStartStop(b *testing.B) { } runBench := func(b *testing.B, opts Options) { - for i := 0; i < b.N; i++ { + for b.Loop() { d, err := Start[KatexInput, KatexOutput](opts) if err != nil { b.Fatal(err) @@ -389,8 +388,7 @@ func BenchmarkExecuteGreet(b *testing.B) { Name: "Person", } - b.ResetTimer() - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { message := Message[person]{ Header: Header{ Version: currentVersion, diff --git a/langs/i18n/i18n_test.go b/langs/i18n/i18n_test.go index a23cee539..7d5a7c8b5 100644 --- a/langs/i18n/i18n_test.go +++ b/langs/i18n/i18n_test.go @@ -507,7 +507,7 @@ func BenchmarkI18nTranslate(b *testing.B) { b.Run(test.name, func(b *testing.B) { tp := prepareTranslationProvider(b, test, v) b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { f := tp.t.Func(test.lang) actual := f(context.Background(), test.id, test.args) if actual != test.expected { diff --git a/langs/language_test.go b/langs/language_test.go index 33240f3f4..e8d319f04 100644 --- a/langs/language_test.go +++ b/langs/language_test.go @@ -57,7 +57,7 @@ func BenchmarkCollator(b *testing.B) { b.Run("Single", func(b *testing.B) { coll := &Collator{c: collate.New(language.English, collate.Loose)} - for i := 0; i < b.N; i++ { + for b.Loop() { doWork(coll) } }) diff --git a/markup/goldmark/autoid_test.go b/markup/goldmark/autoid_test.go index e0770d86c..a2a7551d0 100644 --- a/markup/goldmark/autoid_test.go +++ b/markup/goldmark/autoid_test.go @@ -74,7 +74,6 @@ tabspace } for i, input := range testlines { - input := input expect := expectlines[i] c.Run(input, func(c *qt.C) { b := []byte(input) @@ -100,8 +99,8 @@ func TestSanitizeAnchorNameBlackfriday(t *testing.T) { func BenchmarkSanitizeAnchorName(b *testing.B) { input := []byte("God is good: 神真美好") - b.ResetTimer() - for i := 0; i < b.N; i++ { + + for b.Loop() { result := sanitizeAnchorName(input, goldmark_config.AutoIDTypeGitHub) if len(result) != 24 { b.Fatalf("got %d", len(result)) @@ -111,8 +110,8 @@ func BenchmarkSanitizeAnchorName(b *testing.B) { func BenchmarkSanitizeAnchorNameAsciiOnly(b *testing.B) { input := []byte("God is good: 神真美好") - b.ResetTimer() - for i := 0; i < b.N; i++ { + + for b.Loop() { result := sanitizeAnchorName(input, goldmark_config.AutoIDTypeGitHubAscii) if len(result) != 12 { b.Fatalf("got %d", len(result)) @@ -122,8 +121,8 @@ func BenchmarkSanitizeAnchorNameAsciiOnly(b *testing.B) { func BenchmarkSanitizeAnchorNameBlackfriday(b *testing.B) { input := []byte("God is good: 神真美好") - b.ResetTimer() - for i := 0; i < b.N; i++ { + + for b.Loop() { result := sanitizeAnchorName(input, goldmark_config.AutoIDTypeBlackfriday) if len(result) != 24 { b.Fatalf("got %d", len(result)) @@ -133,8 +132,8 @@ func BenchmarkSanitizeAnchorNameBlackfriday(b *testing.B) { func BenchmarkSanitizeAnchorNameString(b *testing.B) { input := "God is good: 神真美好" - b.ResetTimer() - for i := 0; i < b.N; i++ { + + for b.Loop() { result := sanitizeAnchorNameString(input, goldmark_config.AutoIDTypeGitHub) if len(result) != 24 { b.Fatalf("got %d", len(result)) diff --git a/markup/goldmark/codeblocks/codeblocks_integration_test.go b/markup/goldmark/codeblocks/codeblocks_integration_test.go index 2fd4fa170..c4da3d2e4 100644 --- a/markup/goldmark/codeblocks/codeblocks_integration_test.go +++ b/markup/goldmark/codeblocks/codeblocks_integration_test.go @@ -339,7 +339,6 @@ Common }{ {"issue-9819", "asdf\n: {#myid}"}, } { - test := test t.Run(test.name, func(t *testing.T) { t.Parallel() b := hugolib.NewIntegrationTestBuilder( diff --git a/markup/goldmark/goldmark_integration_test.go b/markup/goldmark/goldmark_integration_test.go index a6eac4e48..8dc24593f 100644 --- a/markup/goldmark/goldmark_integration_test.go +++ b/markup/goldmark/goldmark_integration_test.go @@ -284,9 +284,7 @@ D. builders[i] = hugolib.NewIntegrationTestBuilder(cfg) } - b.ResetTimer() - - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { builders[i].Build() } } @@ -345,7 +343,7 @@ FENCE b.ResetTimer() - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { builders[i].Build() } } diff --git a/markup/goldmark/hugocontext/hugocontext.go b/markup/goldmark/hugocontext/hugocontext.go index 7a556083c..8afe64b7f 100644 --- a/markup/goldmark/hugocontext/hugocontext.go +++ b/markup/goldmark/hugocontext/hugocontext.go @@ -77,8 +77,8 @@ func (n *HugoContext) Dump(source []byte, level int) { } func (n *HugoContext) parseAttrs(attrBytes []byte) { - keyPairs := bytes.Split(attrBytes, []byte(" ")) - for _, keyPair := range keyPairs { + keyPairs := bytes.SplitSeq(attrBytes, []byte(" ")) + for keyPair := range keyPairs { kv := bytes.Split(keyPair, []byte("=")) if len(kv) != 2 { continue diff --git a/markup/goldmark/hugocontext/hugocontext_test.go b/markup/goldmark/hugocontext/hugocontext_test.go index 62769f4d0..597190012 100644 --- a/markup/goldmark/hugocontext/hugocontext_test.go +++ b/markup/goldmark/hugocontext/hugocontext_test.go @@ -28,7 +28,7 @@ func TestWrap(t *testing.T) { } func BenchmarkWrap(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { Wrap([]byte("test"), 42) } } diff --git a/markup/highlight/config.go b/markup/highlight/config.go index b19e9ec1b..fff9bfeca 100644 --- a/markup/highlight/config.go +++ b/markup/highlight/config.go @@ -197,7 +197,7 @@ func parseHighlightOptions(in string) (map[string]any, error) { return opts, nil } - for _, v := range strings.Split(in, ",") { + for v := range strings.SplitSeq(in, ",") { keyVal := strings.Split(v, "=") key := strings.Trim(keyVal[0], " ") if len(keyVal) != 2 { @@ -265,8 +265,8 @@ func hlLinesToRanges(startLine int, s string) ([][2]int, error) { // 1-2 3 // 1 3-4 // 1 3-4 - fields := strings.Split(s, " ") - for _, field := range fields { + fields := strings.SplitSeq(s, " ") + for field := range fields { field = strings.TrimSpace(field) if field == "" { continue diff --git a/markup/internal/external.go b/markup/internal/external.go index dc8cc61c2..dcb8932ca 100644 --- a/markup/internal/external.go +++ b/markup/internal/external.go @@ -37,7 +37,7 @@ func ExternallyRenderContent( // Most external helpers exit w/ non-zero exit code only if severe, i.e. // halting errors occurred. -> log stderr output regardless of state of err - for _, item := range strings.Split(cmderr.String(), "\n") { + for item := range strings.SplitSeq(cmderr.String(), "\n") { item := strings.TrimSpace(item) if item != "" { if err == nil { diff --git a/markup/tableofcontents/tableofcontents_test.go b/markup/tableofcontents/tableofcontents_test.go index b07d9e3ad..d85156150 100644 --- a/markup/tableofcontents/tableofcontents_test.go +++ b/markup/tableofcontents/tableofcontents_test.go @@ -204,12 +204,12 @@ func BenchmarkToc(b *testing.B) { b.Run("Build", func(b *testing.B) { var builders []Builder - for i := 0; i < b.N; i++ { + for b.Loop() { builders = append(builders, newTestTocBuilder()) } b.ResetTimer() - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { b := builders[i] b.Build() } @@ -218,7 +218,7 @@ func BenchmarkToc(b *testing.B) { b.Run("ToHTML", func(b *testing.B) { tocs := newTocs(b.N) b.ResetTimer() - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { toc := tocs[i] toc.ToHTML(1, -1, false) } diff --git a/media/mediaType_test.go b/media/mediaType_test.go index 3b8e099b8..43504ac79 100644 --- a/media/mediaType_test.go +++ b/media/mediaType_test.go @@ -194,7 +194,7 @@ func TestToJSON(t *testing.T) { func BenchmarkTypeOps(b *testing.B) { mt := Builtin.MPEGType mts := DefaultTypes - for i := 0; i < b.N; i++ { + for b.Loop() { ff := mt.FirstSuffix _ = ff.FullSuffix _ = mt.IsZero() diff --git a/metrics/metrics_test.go b/metrics/metrics_test.go index 6e799a393..83dc1433f 100644 --- a/metrics/metrics_test.go +++ b/metrics/metrics_test.go @@ -62,8 +62,7 @@ func BenchmarkHowSimilar(b *testing.B) { s1 := "Hugo is cool and " + strings.Repeat("fun ", 10) + "!" s2 := "Hugo is cool and " + strings.Repeat("cool ", 10) + "!" - b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { howSimilar(s1, s2) } } diff --git a/modules/collect.go b/modules/collect.go index bf027b372..9a86c8140 100644 --- a/modules/collect.go +++ b/modules/collect.go @@ -22,6 +22,7 @@ import ( "os" "path/filepath" "regexp" + "slices" "strings" "time" @@ -148,11 +149,8 @@ func filterDuplicateMounts(mounts []Mount) []Mount { var x []Mount for _, m1 := range mounts { var found bool - for _, m2 := range x { - if m1.Equal(m2) { - found = true - break - } + if slices.ContainsFunc(x, m1.Equal) { + found = true } if !found { x = append(x, m1) diff --git a/parser/metadecoders/decoder_test.go b/parser/metadecoders/decoder_test.go index bc5e93d16..678197f7d 100644 --- a/parser/metadecoders/decoder_test.go +++ b/parser/metadecoders/decoder_test.go @@ -216,7 +216,7 @@ c: "d" `) - for i := 0; i < b.N; i++ { + for b.Loop() { _, err := d.UnmarshalToMap(data, YAML) if err != nil { b.Fatal(err) @@ -256,7 +256,7 @@ params: for _, tt := range yamlTests { b.Run(tt.Title+" no validation", func(b *testing.B) { - for range b.N { + for b.Loop() { var v any if err := unmarshalYamlNoValidation(tt.Content, &v); err != nil { b.Fatal(err) @@ -265,7 +265,7 @@ params: }) b.Run(tt.Title+" with validation", func(b *testing.B) { - for range b.N { + for b.Loop() { var v any err := UnmarshalYaml(tt.Content, &v) if tt.IsExpectedToFailValidation { diff --git a/parser/pageparser/pageparser_shortcode_test.go b/parser/pageparser/pageparser_shortcode_test.go index 976597af2..47c33a86d 100644 --- a/parser/pageparser/pageparser_shortcode_test.go +++ b/parser/pageparser/pageparser_shortcode_test.go @@ -280,8 +280,8 @@ func BenchmarkShortcodeLexer(b *testing.B) { testInputs[i] = []byte(input.input) } var cfg Config - b.ResetTimer() - for i := 0; i < b.N; i++ { + + for b.Loop() { for _, input := range testInputs { _, err := collectWithConfig(input, true, lexMainSection, cfg) if err != nil { diff --git a/parser/pageparser/pageparser_test.go b/parser/pageparser/pageparser_test.go index c6bedbd6f..de7d2e140 100644 --- a/parser/pageparser/pageparser_test.go +++ b/parser/pageparser/pageparser_test.go @@ -40,8 +40,7 @@ This is some summary. This is some summary. This is some summary. This is some s input := []byte(start + strings.Repeat(strings.Repeat("this is text", 30)+"{{< myshortcode >}}This is some inner content.{{< /myshortcode >}}", 10)) cfg := Config{} - b.ResetTimer() - for i := 0; i < b.N; i++ { + for b.Loop() { if _, err := parseBytes(input, cfg, lexIntroSection); err != nil { b.Fatal(err) } @@ -90,13 +89,13 @@ func BenchmarkHasShortcode(b *testing.B) { withShortcode := strings.Repeat("this is text", 30) + "{{< myshortcode >}}This is some inner content.{{< /myshortcode >}}" + strings.Repeat("this is text", 30) withoutShortcode := strings.Repeat("this is text", 30) + "This is some inner content." + strings.Repeat("this is text", 30) b.Run("Match", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { HasShortcode(withShortcode) } }) b.Run("NoMatch", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { HasShortcode(withoutShortcode) } }) diff --git a/publisher/htmlElementsCollector_test.go b/publisher/htmlElementsCollector_test.go index 36447258e..2e6ebdf21 100644 --- a/publisher/htmlElementsCollector_test.go +++ b/publisher/htmlElementsCollector_test.go @@ -244,7 +244,7 @@ func BenchmarkElementsCollectorWriter(b *testing.B) {