Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metrics: use
regexp.MatchString
for metric name check (#4047)
`(*Regexp).Match` have a string-based equivalent `(*Regexp).MatchString`. We should use the string version to avoid unnecessary `[]byte` conversions. Benchmark: func BenchmarkMatch(b *testing.B) { for i := 0; i < b.N; i++ { if match := compileNameRegex.Match([]byte("my_metric_name1")); !match { b.Fail() } } } func BenchmarkMatchString(b *testing.B) { for i := 0; i < b.N; i++ { if match := compileNameRegex.MatchString("my_metric_name1"); !match { b.Fail() } } } Result: goos: linux goarch: amd64 pkg: go.k6.io/k6/metrics cpu: AMD Ryzen 7 PRO 4750U with Radeon Graphics BenchmarkMatch-16 1457095 820.7 ns/op 16 B/op 1 allocs/op BenchmarkMatchString-16 1664458 726.6 ns/op 0 B/op 0 allocs/op PASS coverage: 0.2% of statements ok go.k6.io/k6/metrics 3.983s Signed-off-by: Eng Zer Jun <[email protected]>
- Loading branch information