...

Source file src/github.com/distribution/reference/regexp_bench_test.go

Documentation: github.com/distribution/reference

     1  package reference
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  )
     7  
     8  func BenchmarkParse(b *testing.B) {
     9  	tests := []regexpMatch{
    10  		{
    11  			input: "",
    12  			match: false,
    13  		},
    14  		{
    15  			input: "short",
    16  			match: true,
    17  		},
    18  		{
    19  			input: "simple/name",
    20  			match: true,
    21  		},
    22  		{
    23  			input: "library/ubuntu",
    24  			match: true,
    25  		},
    26  		{
    27  			input: "docker/stevvooe/app",
    28  			match: true,
    29  		},
    30  		{
    31  			input: "aa/aa/aa/aa/aa/aa/aa/aa/aa/bb/bb/bb/bb/bb/bb",
    32  			match: true,
    33  		},
    34  		{
    35  			input: "aa/aa/bb/bb/bb",
    36  			match: true,
    37  		},
    38  		{
    39  			input: "a/a/a/a",
    40  			match: true,
    41  		},
    42  		{
    43  			input: "a/a/a/a/",
    44  			match: false,
    45  		},
    46  		{
    47  			input: "a//a/a",
    48  			match: false,
    49  		},
    50  		{
    51  			input: "a",
    52  			match: true,
    53  		},
    54  		{
    55  			input: "a/aa",
    56  			match: true,
    57  		},
    58  		{
    59  			input: "a/aa/a",
    60  			match: true,
    61  		},
    62  		{
    63  			input: "foo.com",
    64  			match: true,
    65  		},
    66  		{
    67  			input: "foo.com/",
    68  			match: false,
    69  		},
    70  		{
    71  			input: "foo.com:8080/bar",
    72  			match: true,
    73  		},
    74  		{
    75  			input: "foo.com:http/bar",
    76  			match: false,
    77  		},
    78  		{
    79  			input: "foo.com/bar",
    80  			match: true,
    81  		},
    82  		{
    83  			input: "foo.com/bar/baz",
    84  			match: true,
    85  		},
    86  		{
    87  			input: "localhost:8080/bar",
    88  			match: true,
    89  		},
    90  		{
    91  			input: "sub-dom1.foo.com/bar/baz/quux",
    92  			match: true,
    93  		},
    94  		{
    95  			input: "blog.foo.com/bar/baz",
    96  			match: true,
    97  		},
    98  		{
    99  			input: "a^a",
   100  			match: false,
   101  		},
   102  		{
   103  			input: "aa/asdf$$^/aa",
   104  			match: false,
   105  		},
   106  		{
   107  			input: "asdf$$^/aa",
   108  			match: false,
   109  		},
   110  		{
   111  			input: "aa-a/a",
   112  			match: true,
   113  		},
   114  		{
   115  			input: strings.Repeat("a/", 128) + "a",
   116  			match: true,
   117  		},
   118  		{
   119  			input: "a-/a/a/a",
   120  			match: false,
   121  		},
   122  		{
   123  			input: "foo.com/a-/a/a",
   124  			match: false,
   125  		},
   126  		{
   127  			input: "-foo/bar",
   128  			match: false,
   129  		},
   130  		{
   131  			input: "foo/bar-",
   132  			match: false,
   133  		},
   134  		{
   135  			input: "foo-/bar",
   136  			match: false,
   137  		},
   138  		{
   139  			input: "foo/-bar",
   140  			match: false,
   141  		},
   142  		{
   143  			input: "_foo/bar",
   144  			match: false,
   145  		},
   146  		{
   147  			input: "foo_bar",
   148  			match: true,
   149  		},
   150  		{
   151  			input: "foo_bar.com",
   152  			match: true,
   153  		},
   154  		{
   155  			input: "foo_bar.com:8080",
   156  			match: false,
   157  		},
   158  		{
   159  			input: "foo_bar.com:8080/app",
   160  			match: false,
   161  		},
   162  		{
   163  			input: "foo.com/foo_bar",
   164  			match: true,
   165  		},
   166  		{
   167  			input: "____/____",
   168  			match: false,
   169  		},
   170  		{
   171  			input: "_docker/_docker",
   172  			match: false,
   173  		},
   174  		{
   175  			input: "docker_/docker_",
   176  			match: false,
   177  		},
   178  		{
   179  			input: "b.gcr.io/test.example.com/my-app",
   180  			match: true,
   181  		},
   182  		{
   183  			input: "xn--n3h.com/myimage", // ☃.com in punycode
   184  			match: true,
   185  		},
   186  		{
   187  			input: "xn--7o8h.com/myimage", // 🐳.com in punycode
   188  			match: true,
   189  		},
   190  		{
   191  			input: "example.com/xn--7o8h.com/myimage", // 🐳.com in punycode
   192  			match: true,
   193  		},
   194  		{
   195  			input: "example.com/some_separator__underscore/myimage",
   196  			match: true,
   197  		},
   198  		{
   199  			input: "example.com/__underscore/myimage",
   200  			match: false,
   201  		},
   202  		{
   203  			input: "example.com/..dots/myimage",
   204  			match: false,
   205  		},
   206  		{
   207  			input: "example.com/.dots/myimage",
   208  			match: false,
   209  		},
   210  		{
   211  			input: "example.com/nodouble..dots/myimage",
   212  			match: false,
   213  		},
   214  		{
   215  			input: "example.com/nodouble..dots/myimage",
   216  			match: false,
   217  		},
   218  		{
   219  			input: "docker./docker",
   220  			match: false,
   221  		},
   222  		{
   223  			input: ".docker/docker",
   224  			match: false,
   225  		},
   226  		{
   227  			input: "docker-/docker",
   228  			match: false,
   229  		},
   230  		{
   231  			input: "-docker/docker",
   232  			match: false,
   233  		},
   234  		{
   235  			input: "do..cker/docker",
   236  			match: false,
   237  		},
   238  		{
   239  			input: "do__cker:8080/docker",
   240  			match: false,
   241  		},
   242  		{
   243  			input: "do__cker/docker",
   244  			match: true,
   245  		},
   246  		{
   247  			input: "b.gcr.io/test.example.com/my-app",
   248  			match: true,
   249  		},
   250  		{
   251  			input: "registry.io/foo/project--id.module--name.ver---sion--name",
   252  			match: true,
   253  		},
   254  		{
   255  			input: "Asdf.com/foo/bar", // uppercase character in hostname
   256  			match: true,
   257  		},
   258  		{
   259  			input: "Foo/FarB", // uppercase characters in remote name
   260  			match: false,
   261  		},
   262  	}
   263  
   264  	b.ReportAllocs()
   265  	for i := 0; i < b.N; i++ {
   266  		for _, tc := range tests {
   267  			_, _ = Parse(tc.input)
   268  		}
   269  	}
   270  }
   271  

View as plain text