| 62 | } |
| 63 | |
| 64 | func BenchmarkUserDataRedact(b *testing.B) { |
| 65 | defer func() { RedactUserData = defaultRedactUserData }() |
| 66 | |
| 67 | username := UserData("alice") |
| 68 | usernameSlice := UD([]string{"adam", "ben", "jacques"}) |
| 69 | |
| 70 | // We'd expect a minor performance hit when redaction is enabled. |
| 71 | b.Run("Enabled", func(bn *testing.B) { |
| 72 | RedactUserData = true |
| 73 | for i := 0; i < bn.N; i++ { |
| 74 | username.Redact() |
| 75 | } |
| 76 | }) |
| 77 | |
| 78 | b.Run("EnabledSlice", func(bn *testing.B) { |
| 79 | RedactUserData = true |
| 80 | for i := 0; i < bn.N; i++ { |
| 81 | usernameSlice.Redact() |
| 82 | } |
| 83 | }) |
| 84 | |
| 85 | // When redaction is disabled, we should see no performance hit. |
| 86 | b.Run("Disabled", func(bn *testing.B) { |
| 87 | RedactUserData = false |
| 88 | for i := 0; i < bn.N; i++ { |
| 89 | username.Redact() |
| 90 | } |
| 91 | }) |
| 92 | } |
| 93 | |
| 94 | type FakeLogger struct { |
| 95 | } |