Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid allocations with
(*regexp.Regexp).MatchString
(#602)
We should use `(*regexp.Regexp).MatchString` instead of `(*regexp.Regexp).Match([]byte(...))` when matching string to avoid unnecessary `[]byte` conversions and reduce allocations. Example benchmark: func BenchmarkMatch(b *testing.B) { for i := 0; i < b.N; i++ { if match := timeWithSeconds.Match([]byte("06:18:01")); !match { b.Fail() } } } func BenchmarkMatchString(b *testing.B) { for i := 0; i < b.N; i++ { if match := timeWithSeconds.MatchString("06:18:01"); !match { b.Fail() } } } goos: linux goarch: amd64 pkg: github.com/go-co-op/gocron cpu: AMD Ryzen 7 PRO 4750U with Radeon Graphics BenchmarkMatch-16 7213512 223.8 ns/op 8 B/op 1 allocs/op BenchmarkMatchString-16 8484169 145.8 ns/op 0 B/op 0 allocs/op PASS ok github.com/go-co-op/gocron 4.114s Signed-off-by: Eng Zer Jun <[email protected]>
- Loading branch information