Procházet zdrojové kódy

Update: Benchmarks

Leonardo Di Donato před 8 roky
rodič
revize
71c968d4af
3 změnil soubory, kde provedl 52 přidání a 16 odebrání
  1. 43 0
      performance_test.go
  2. 9 1
      tables_test.go
  3. 0 15
      urn_test.go

+ 43 - 0
performance_test.go

@@ -0,0 +1,43 @@
+package urn
+
+import (
+	"fmt"
+	"testing"
+)
+
+var benchs = []testCase{
+	tests[14],
+	tests[2],
+	tests[6],
+	tests[10],
+	tests[11],
+	tests[13],
+	tests[20],
+	tests[23],
+	tests[33],
+	tests[45],
+	tests[47],
+	tests[48],
+	tests[50],
+	tests[52],
+	tests[53],
+	tests[57],
+	tests[62],
+	tests[63],
+	tests[67],
+	tests[60],
+}
+
+func BenchmarkParse(b *testing.B) {
+	for ii, tt := range benchs {
+		outcome := (map[bool]string{true: "ok", false: "no"})[tt.ok]
+		b.Run(
+			fmt.Sprintf("%s/%02d/%s/", outcome, ii, rxpad(tt.in, 45)),
+			func(b *testing.B) {
+				for i := 0; i < b.N; i++ {
+					Parse(tt.in)
+				}
+			},
+		)
+	}
+}

+ 9 - 1
tables_test.go

@@ -1,6 +1,9 @@
 package urn
 
-import "strconv"
+import (
+	"strconv"
+	"strings"
+)
 
 func ierror(index int) string {
 	return "Test case num. " + strconv.Itoa(index+1)
@@ -10,6 +13,11 @@ func herror(index int, test testCase) string {
 	return ierror(index) + ", input \"" + test.in + "\""
 }
 
+func rxpad(str string, lim int) string {
+	str = str + strings.Repeat(" ", lim)
+	return str[:lim]
+}
+
 type testCase struct {
 	in   string // the input
 	ok   bool   // whether it is valid or not

+ 0 - 15
urn_test.go

@@ -1,7 +1,6 @@
 package urn
 
 import (
-	"fmt"
 	"testing"
 
 	"github.com/stretchr/testify/require"
@@ -56,17 +55,3 @@ func TestDefaultPrefixWhenString(t *testing.T) {
 
 	require.Equal(t, "urn:pippo:pluto", u.String())
 }
-
-func BenchmarkParse(b *testing.B) {
-	for ii, tt := range tests {
-		outcome := (map[bool]string{true: "ok", false: "no"})[tt.ok]
-		b.Run(
-			fmt.Sprintf("%s/%02d/%s%0*s/", outcome, ii, tt.in, len(tt.in)-80, " "),
-			func(b *testing.B) {
-				for i := 0; i < b.N; i++ {
-					Parse(tt.in)
-				}
-			},
-		)
-	}
-}