| 1 | package swarscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/ |
| 2 | |
| 3 | import ( |
| 4 | "bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/" |
| 5 | "encoding/binaryscip-go gomod github.com/golang/go/src go1.25.0 `encoding/binary`/" |
| 6 | "strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/" |
| 7 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 8 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 9 | |
| 10 | "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/" |
| 11 | ) |
| 12 | |
| 13 | // The benchmarks below compare the SWAR primitives against their stdlib |
| 14 | // counterparts, using the fiber-vs-default sub-run naming shared with the |
| 15 | // strings and bytes packages. |
| 16 | // The primitives are exported as building blocks, so each benchmark measures |
| 17 | // the canonical loop composed from them (documented in the examples), not a |
| 18 | // bare primitive call: that is the unit of work a stdlib function performs. |
| 19 | // The composed loops live below and are pinned to the stdlib results by |
| 20 | // Test_BenchLoops_MatchStdlib. |
| 21 | |
| 22 | // swarIndexByte is ExampleZeroLanes' canonical first-match scan: broadcast |
| 23 | // once, scan full words, and finish 8+ byte inputs with one overlapping word. |
| 24 | func swarIndexBytescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/swarIndexByte().(s string, c byte) int { |
| 25 | n := len(s) |
| 26 | if n < WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/WordLen. { |
| 27 | for i := range n { |
| 28 | if s[i] == c { |
| 29 | return i |
| 30 | } |
| 31 | } |
| 32 | return -1 |
| 33 | } |
| 34 | needle := Broadcastscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/Broadcast().(c) |
| 35 | i := 0 |
| 36 | for ; i+WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/WordLen. <= n; i += WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/WordLen. { |
| 37 | if m := ZeroLanesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/ZeroLanes().(Load8scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/Load8().(s, i) ^ needle); m != 0 { |
| 38 | return i + FirstLanescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/FirstLane().(m) |
| 39 | } |
| 40 | } |
| 41 | if i == n { |
| 42 | return -1 |
| 43 | } |
| 44 | if m := ZeroLanesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/ZeroLanes().(Load8scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/Load8().(s, n-WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/WordLen.) ^ needle); m != 0 { |
| 45 | return n - WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/WordLen. + FirstLanescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/FirstLane().(m) |
| 46 | } |
| 47 | return -1 |
| 48 | } |
| 49 | |
| 50 | // swarLastIndexByte is the reverse scan: MatchByteMask's exact per-lane |
| 51 | // result feeds LastLane, and the sub-word head falls back to scalar code. |
| 52 | func swarLastIndexBytescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/swarLastIndexByte().(b []byte, c byte) int { |
| 53 | i := len(b) |
| 54 | for ; i >= WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/WordLen.; i -= WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/WordLen. { |
| 55 | if m := MatchByteMaskscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/MatchByteMask().(Load8scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/Load8().(b, i-WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/WordLen.), c); m != 0 { |
| 56 | return i - WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/WordLen. + LastLanescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/LastLane().(m) |
| 57 | } |
| 58 | } |
| 59 | for i--; i >= 0; i-- { |
| 60 | if b[i] == c { |
| 61 | return i |
| 62 | } |
| 63 | } |
| 64 | return -1 |
| 65 | } |
| 66 | |
| 67 | // swarIndexDigit finds the first ASCII digit via MatchRangeMask, with a |
| 68 | // scalar tail for the trailing sub-word bytes. |
| 69 | func swarIndexDigitscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/swarIndexDigit().(s string) int { |
| 70 | i := 0 |
| 71 | for ; i+WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/WordLen. <= len(s); i += WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/WordLen. { |
| 72 | if m := MatchRangeMaskscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/MatchRangeMask().(Load8scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/Load8().(s, i), '0', '9'); m != 0 { |
| 73 | return i + FirstLanescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/FirstLane().(m) |
| 74 | } |
| 75 | } |
| 76 | for ; i < len(s); i++ { |
| 77 | if s[i] >= '0' && s[i] <= '9' { |
| 78 | return i |
| 79 | } |
| 80 | } |
| 81 | return -1 |
| 82 | } |
| 83 | |
| 84 | // swarToLower lower-cases ASCII in place, one word at a time, with a scalar |
| 85 | // tail — the loop internal/caseconv builds from the same primitives. |
| 86 | func swarToLowerscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/swarToLower().(b []byte) { |
| 87 | i := 0 |
| 88 | for ; i+WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/WordLen. <= len(b); i += WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/WordLen. { |
| 89 | Store8scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/Store8().(b, i, ToLowerWordscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/ToLowerWord().(Load8scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/Load8().(b, i))) |
| 90 | } |
| 91 | for ; i < len(b); i++ { |
| 92 | if c := b[i]; c >= 'A' && c <= 'Z' { |
| 93 | b[i] = c + ('a' - 'A') |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | // Test_BenchLoops_MatchStdlib pins the composed benchmark loops to the |
| 99 | // stdlib functions they are measured against, across sub-word, exact-word, |
| 100 | // and multi-word lengths with the needle at every position and absent. |
| 101 | func Test_BenchLoops_MatchStdlibscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/Test_BenchLoops_MatchStdlib().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 102 | t.Parallelscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Parallel().() |
| 103 | sizes := []int{0, 1, 7, 8, 9, 16, 31, 64, 512} |
| 104 | for _, n := range sizes { |
| 105 | src := make([]byte, n) |
| 106 | for i := range src { |
| 107 | src[i] = 'A' + byte(i%23) // uppercase, no digits, no needle bytes |
| 108 | } |
| 109 | for at := -1; at < n; at++ { |
| 110 | b := append([]byte(nil), src...) |
| 111 | if at >= 0 { |
| 112 | b[at] = ',' |
| 113 | } |
| 114 | s := string(b) |
| 115 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.IndexBytescip-go gomod github.com/golang/go/src go1.25.0 strings/IndexByte().(s, ','), swarIndexBytescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/swarIndexByte().(s, ','), "IndexByte size %d at %d", n, at) |
| 116 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.LastIndexBytescip-go gomod github.com/golang/go/src go1.25.0 bytes/LastIndexByte().(b, ','), swarLastIndexBytescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/swarLastIndexByte().(b, ','), "LastIndexByte size %d at %d", n, at) |
| 117 | |
| 118 | d := append([]byte(nil), src...) |
| 119 | if at >= 0 { |
| 120 | d[at] = '7' |
| 121 | } |
| 122 | // Pin against strings.IndexAny — the same stdlib function the |
| 123 | // benchmark's default leg measures. |
| 124 | ds := string(d) |
| 125 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.IndexAnyscip-go gomod github.com/golang/go/src go1.25.0 strings/IndexAny().(ds, "0123456789"), swarIndexDigitscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/swarIndexDigit().(ds), "IndexDigit size %d at %d", n, at) |
| 126 | } |
| 127 | lower := append([]byte(nil), src...) |
| 128 | swarToLowerscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/swarToLower().(lower) |
| 129 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, string(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.ToLowerscip-go gomod github.com/golang/go/src go1.25.0 bytes/ToLower().(src)), string(lower), "ToLower size %d", n) |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | var benchSizesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/benchSizes. = []int{7, 8, 16, 32, 64, 512} |
| 134 | |
| 135 | func benchInputscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/benchInput().(size, needleAt int, needle byte) []byte { |
| 136 | b := make([]byte, size) |
| 137 | for i := range b { |
| 138 | b[i] = 'a' + byte(i%23) |
| 139 | } |
| 140 | if needleAt >= 0 && needleAt < size { |
| 141 | b[needleAt] = needle |
| 142 | } |
| 143 | return b |
| 144 | } |
| 145 | |
| 146 | func Benchmark_Load8scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/Benchmark_Load8().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 147 | buf := benchInputscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/benchInput().(4096, -1, 0) |
| 148 | b.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Run().("fiber", func(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 149 | b.SetBytesscip-go gomod github.com/golang/go/src go1.25.0 testing/B#SetBytes().(int64(len(buf))) |
| 150 | var acc uint64 |
| 151 | for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() { |
| 152 | for i := 0; i+WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/WordLen. <= len(buf); i += WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/WordLen. { |
| 153 | acc += Load8scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/Load8().(buf, i) |
| 154 | } |
| 155 | } |
| 156 | _ = acc |
| 157 | }) |
| 158 | b.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Run().("default", func(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 159 | b.SetBytesscip-go gomod github.com/golang/go/src go1.25.0 testing/B#SetBytes().(int64(len(buf))) |
| 160 | var acc uint64 |
| 161 | for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() { |
| 162 | for i := 0; i+WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/WordLen. <= len(buf); i += WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/WordLen. { |
| 163 | acc += binaryscip-go gomod github.com/golang/go/src go1.25.0 `encoding/binary`/.LittleEndianscip-go gomod github.com/golang/go/src go1.25.0 `encoding/binary`/LittleEndian..Uint64scip-go gomod github.com/golang/go/src go1.25.0 `encoding/binary`/littleEndian#Uint64().(buf[i:]) |
| 164 | } |
| 165 | } |
| 166 | _ = acc |
| 167 | }) |
| 168 | } |
| 169 | |
| 170 | func Benchmark_Store8scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/Benchmark_Store8().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 171 | buf := make([]byte, 4096) |
| 172 | w := Broadcastscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/Broadcast().('x') |
| 173 | b.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Run().("fiber", func(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 174 | b.SetBytesscip-go gomod github.com/golang/go/src go1.25.0 testing/B#SetBytes().(int64(len(buf))) |
| 175 | for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() { |
| 176 | for i := 0; i+WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/WordLen. <= len(buf); i += WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/WordLen. { |
| 177 | Store8scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/Store8().(buf, i, w) |
| 178 | } |
| 179 | } |
| 180 | }) |
| 181 | b.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Run().("default", func(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 182 | b.SetBytesscip-go gomod github.com/golang/go/src go1.25.0 testing/B#SetBytes().(int64(len(buf))) |
| 183 | for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() { |
| 184 | for i := 0; i+WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/WordLen. <= len(buf); i += WordLenscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/WordLen. { |
| 185 | binaryscip-go gomod github.com/golang/go/src go1.25.0 `encoding/binary`/.LittleEndianscip-go gomod github.com/golang/go/src go1.25.0 `encoding/binary`/LittleEndian..PutUint64scip-go gomod github.com/golang/go/src go1.25.0 `encoding/binary`/littleEndian#PutUint64().(buf[i:], w) |
| 186 | } |
| 187 | } |
| 188 | }) |
| 189 | } |
| 190 | |
| 191 | func Benchmark_IndexBytescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/Benchmark_IndexByte().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 192 | for _, size := range benchSizesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/benchSizes. { |
| 193 | s := string(benchInputscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/benchInput().(size, size-1, ',')) // worst case: match at the very end |
| 194 | b.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Run().(strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.Itoascip-go gomod github.com/golang/go/src go1.25.0 strconv/Itoa().(size)+"B/fiber", func(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 195 | b.SetBytesscip-go gomod github.com/golang/go/src go1.25.0 testing/B#SetBytes().(int64(size)) |
| 196 | var r int |
| 197 | for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() { |
| 198 | r = swarIndexBytescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/swarIndexByte().(s, ',') |
| 199 | } |
| 200 | _ = r |
| 201 | }) |
| 202 | b.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Run().(strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.Itoascip-go gomod github.com/golang/go/src go1.25.0 strconv/Itoa().(size)+"B/default", func(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 203 | b.SetBytesscip-go gomod github.com/golang/go/src go1.25.0 testing/B#SetBytes().(int64(size)) |
| 204 | var r int |
| 205 | for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() { |
| 206 | r = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.IndexBytescip-go gomod github.com/golang/go/src go1.25.0 strings/IndexByte().(s, ',') |
| 207 | } |
| 208 | _ = r |
| 209 | }) |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | func Benchmark_LastIndexBytescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/Benchmark_LastIndexByte().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 214 | for _, size := range benchSizesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/benchSizes. { |
| 215 | buf := benchInputscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/benchInput().(size, 0, ',') // worst case for a reverse scan: match at the start |
| 216 | b.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Run().(strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.Itoascip-go gomod github.com/golang/go/src go1.25.0 strconv/Itoa().(size)+"B/fiber", func(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 217 | b.SetBytesscip-go gomod github.com/golang/go/src go1.25.0 testing/B#SetBytes().(int64(size)) |
| 218 | var r int |
| 219 | for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() { |
| 220 | r = swarLastIndexBytescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/swarLastIndexByte().(buf, ',') |
| 221 | } |
| 222 | _ = r |
| 223 | }) |
| 224 | b.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Run().(strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.Itoascip-go gomod github.com/golang/go/src go1.25.0 strconv/Itoa().(size)+"B/default", func(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 225 | b.SetBytesscip-go gomod github.com/golang/go/src go1.25.0 testing/B#SetBytes().(int64(size)) |
| 226 | var r int |
| 227 | for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() { |
| 228 | r = bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.LastIndexBytescip-go gomod github.com/golang/go/src go1.25.0 bytes/LastIndexByte().(buf, ',') |
| 229 | } |
| 230 | _ = r |
| 231 | }) |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | func Benchmark_IndexDigitscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/Benchmark_IndexDigit().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 236 | for _, size := range benchSizesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/benchSizes. { |
| 237 | s := string(benchInputscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/benchInput().(size, size-1, '7')) |
| 238 | b.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Run().(strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.Itoascip-go gomod github.com/golang/go/src go1.25.0 strconv/Itoa().(size)+"B/fiber", func(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 239 | b.SetBytesscip-go gomod github.com/golang/go/src go1.25.0 testing/B#SetBytes().(int64(size)) |
| 240 | var r int |
| 241 | for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() { |
| 242 | r = swarIndexDigitscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/swarIndexDigit().(s) |
| 243 | } |
| 244 | _ = r |
| 245 | }) |
| 246 | b.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Run().(strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.Itoascip-go gomod github.com/golang/go/src go1.25.0 strconv/Itoa().(size)+"B/default", func(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 247 | b.SetBytesscip-go gomod github.com/golang/go/src go1.25.0 testing/B#SetBytes().(int64(size)) |
| 248 | var r int |
| 249 | for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() { |
| 250 | r = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.IndexAnyscip-go gomod github.com/golang/go/src go1.25.0 strings/IndexAny().(s, "0123456789") |
| 251 | } |
| 252 | _ = r |
| 253 | }) |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | func Benchmark_ToLowerWordscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/Benchmark_ToLowerWord().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 258 | for _, size := range benchSizesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/benchSizes. { |
| 259 | template := bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.ToUpperscip-go gomod github.com/golang/go/src go1.25.0 bytes/ToUpper().(benchInputscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/benchInput().(size, -1, 0)) |
| 260 | b.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Run().(strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.Itoascip-go gomod github.com/golang/go/src go1.25.0 strconv/Itoa().(size)+"B/fiber", func(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 261 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.25.0 testing/B#ReportAllocs().() |
| 262 | b.SetBytesscip-go gomod github.com/golang/go/src go1.25.0 testing/B#SetBytes().(int64(size)) |
| 263 | work := make([]byte, len(template)) |
| 264 | // The copy is timed on purpose: it resets the in-place buffer |
| 265 | // every iteration (as the strings package's fiber/unsafe legs |
| 266 | // do) and stands in for the per-iteration allocation the |
| 267 | // default leg pays inside bytes.ToLower. |
| 268 | for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() { |
| 269 | copy(work, template) |
| 270 | swarToLowerscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/swar`/swarToLower().(work) |
| 271 | } |
| 272 | }) |
| 273 | b.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Run().(strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.Itoascip-go gomod github.com/golang/go/src go1.25.0 strconv/Itoa().(size)+"B/default", func(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 274 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.25.0 testing/B#ReportAllocs().() |
| 275 | b.SetBytesscip-go gomod github.com/golang/go/src go1.25.0 testing/B#SetBytes().(int64(size)) |
| 276 | var r []byte |
| 277 | for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() { |
| 278 | r = bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.ToLowerscip-go gomod github.com/golang/go/src go1.25.0 bytes/ToLower().(template) |
| 279 | } |
| 280 | _ = r |
| 281 | }) |
| 282 | } |
| 283 | } |