Debian Codegraph @

internal/config/types/bench_test.go

raw
1 package types_test
2
3 import (
4 "testing"
5
6 "github.com/jkroepke/openvpn-auth-oauth2/v2/internal/config/types"
7 )
8
9 func BenchmarkURLUnmarshalText(b *testing.B) {
10 input := []byte("https://issuer.example.com/oauth2/v2/authorize?audience=vpn&prompt=login")
11
12 var parsedURL types.URL
13
14 b.ReportAllocs()
15 b.ResetTimer()
16
17 for b.Loop() {
18 if err := parsedURL.UnmarshalText(input); err != nil {
19 b.Fatal(err)
20 }
21 }
22
23 _ = parsedURL
24 }
25
26 func BenchmarkStringSliceUnmarshalText(b *testing.B) {
27 for _, tc := range []struct {
28 name string
29 input []byte
30 }{
31 {
32 name: "short",
33 input: []byte("openid,profile,email"),
34 },
35 {
36 name: "long",
37 input: []byte("alpha,beta,gamma,delta,epsilon,zeta,eta,theta,iota,kappa,lambda,mu"),
38 },
39 } {
40 b.Run(tc.name, func(b *testing.B) {
41 var stringSlice types.StringSlice
42
43 b.ReportAllocs()
44 b.ResetTimer()
45
46 for b.Loop() {
47 if err := stringSlice.UnmarshalText(tc.input); err != nil {
48 b.Fatal(err)
49 }
50 }
51
52 _ = stringSlice
53 })
54 }
55 }
56
57 func BenchmarkRegexpSliceUnmarshalText(b *testing.B) {
58 for _, tc := range []struct {
59 name string
60 input []byte
61 }{
62 {
63 name: "short",
64 input: []byte("group1,group2,group3"),
65 },
66 {
67 name: "anchored-like-patterns",
68 input: []byte("client-.*,admin-.*,support-.*"),
69 },
70 } {
71 b.Run(tc.name, func(b *testing.B) {
72 var regexpSlice types.RegexpSlice
73
74 b.ReportAllocs()
75 b.ResetTimer()
76
77 for b.Loop() {
78 if err := regexpSlice.UnmarshalText(tc.input); err != nil {
79 b.Fatal(err)
80 }
81 }
82
83 _ = regexpSlice
84 })
85 }
86 }