Skip to content

Commit

Permalink
Better bench plus fix a little bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lucapette committed Nov 21, 2022
1 parent c0e27a9 commit 25afac4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions pkg/fakedata/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ func localPhone(options string) (func() string, error) {
}

switch numDigits {
case 8:
return integer("10000000,99999999")
case 9:
return integer("100000000,999999999")
case 10:
Expand Down
19 changes: 13 additions & 6 deletions pkg/fakedata/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,21 @@ func BenchmarkInt(b *testing.B) {
func BenchmarkPhoneLocal(b *testing.B) {
phoneLocal := gens.FindByName("phone.local")

phoneLocalFunc, err := phoneLocal.CustomFunc("11")
if err != nil {
b.Fatalf("cannot create phone.local: %s", err)
digits := []string{"8", "9", "10", "11", "12"}

for _, digit := range digits {
b.Run("phone.local:"+digit, func(b *testing.B) {
phoneLocalFunc, err := phoneLocal.CustomFunc(digit)
if err != nil {
b.Fatalf("cannot create phone.local: %s", err)
}

for i := 0; i < b.N; i++ {
phoneLocalFunc()
}
})
}

for i := 0; i < b.N; i++ {
phoneLocalFunc()
}
}

func BenchmarkFile(b *testing.B) {
Expand Down

0 comments on commit 25afac4

Please sign in to comment.