func benchPhoneMnemonics(b *testing.B, size int) { number := epiutil.RandStr(size, "0123456789", rand.NewSource(int64(size))) b.ResetTimer() for i := 0; i < b.N; i++ { PhoneMnemonics(number) } }
func benchCanFormPalindrome(b *testing.B, size int) { s := epiutil.RandStr(size, "abcdefghijklmnopqrstuvwxyz", rand.NewSource(int64(size))) b.ResetTimer() for i := 0; i < b.N; i++ { CanFormPalindrome(s) } }
func benchReverseFn(b *testing.B, size int, fn reverseFn) { s := epiutil.RandStr(size, "☺ abcdefghijklm nopqrstuvwxyz 世界", rand.NewSource(int64(size))) b.ResetTimer() for i := 0; i < b.N; i++ { fn(s) } }
func benchCountOccurrences(b *testing.B, size int) { s := epiutil.RandStr(size, "0123456789abcdefghijklmnopqrstuvwxyz", rand.NewSource(int64(size))) b.ResetTimer() for i := 0; i < b.N; i++ { CountOccurrences(s) } }
func benchReverseWords(b *testing.B, size int) { s := epiutil.RandStr(size, "The quick brown fox jumps over the lazy dog", rand.NewSource(int64(size))) // Pangram. b.ResetTimer() for i := 0; i < b.N; i++ { ReverseWords(s) } }
func benchIsLetterSubset(b *testing.B, size int) { m := epiutil.RandStr(size, "ab cd ef gh ij kl mn op qr st uv wx yz", rand.NewSource(int64(size))) l := m[:size/2] b.ResetTimer() for i := 0; i < b.N; i++ { IsLetterSubset(l, m) } }
func benchIndexFn(b *testing.B, size int, fn indexFn) { s := epiutil.RandStr(size, "☺ abcdefghijklmnopqrstuvwxyz 世界", rand.NewSource(time.Now().UnixNano())) p := s[size/3 : size*2/3] b.ResetTimer() for i := 0; i < b.N; i++ { fn(s, p) } }
func benchGroupAnagrams(b *testing.B, n, m int) { words := make([]string, n) for i := 0; i < n; i++ { words[i] = epiutil.RandStr(m, "abcdefghijklmnopqrstuvwxyz", rand.NewSource(int64(i))) } b.ResetTimer() for i := 0; i < b.N; i++ { GroupAnagrams(words) } }
func benchRLEDecode(b *testing.B, size int) { s, ok := RLEEncode(epiutil.RandStr(size, "abcdefghijklmnopqrstuvwxyz", rand.NewSource(int64(size)))) if !ok { b.Error("RLEEncode did not encode string properly") } b.ResetTimer() for i := 0; i < b.N; i++ { RLEDecode(s) } }