| 100 | } |
| 101 | |
| 102 | func BenchmarkRedactOnLog(b *testing.B) { |
| 103 | SetUpBenchmarkLogging(b, LevelWarn, KeyAll) |
| 104 | |
| 105 | defer func() { RedactUserData = defaultRedactUserData }() |
| 106 | |
| 107 | b.Run("WarnPlain", func(b *testing.B) { |
| 108 | ctx := TestCtx(b) |
| 109 | for i := 0; i < b.N; i++ { |
| 110 | WarnfCtx(ctx, "Log: %s", "Fixed String") |
| 111 | } |
| 112 | }) |
| 113 | |
| 114 | b.Run("WarnRedactTrueNotUD", func(b *testing.B) { |
| 115 | ctx := TestCtx(b) |
| 116 | RedactUserData = true |
| 117 | for i := 0; i < b.N; i++ { |
| 118 | WarnfCtx(ctx, "Log: %s", FakeLogger{}) |
| 119 | } |
| 120 | }) |
| 121 | |
| 122 | b.Run("WarnRedactTrueUD", func(b *testing.B) { |
| 123 | ctx := TestCtx(b) |
| 124 | RedactUserData = true |
| 125 | for i := 0; i < b.N; i++ { |
| 126 | WarnfCtx(ctx, "Log: %s", UD(FakeLogger{})) |
| 127 | } |
| 128 | }) |
| 129 | |
| 130 | b.Run("WarnRedactFalseNotUD", func(b *testing.B) { |
| 131 | ctx := TestCtx(b) |
| 132 | RedactUserData = false |
| 133 | for i := 0; i < b.N; i++ { |
| 134 | WarnfCtx(ctx, "Log: %s", FakeLogger{}) |
| 135 | } |
| 136 | }) |
| 137 | |
| 138 | b.Run("WarnRedactFalseUD", func(b *testing.B) { |
| 139 | ctx := TestCtx(b) |
| 140 | RedactUserData = false |
| 141 | for i := 0; i < b.N; i++ { |
| 142 | WarnfCtx(ctx, "Log: %s", UD(FakeLogger{})) |
| 143 | } |
| 144 | }) |
| 145 | |
| 146 | b.Run("DebugPlain", func(b *testing.B) { |
| 147 | ctx := TestCtx(b) |
| 148 | for i := 0; i < b.N; i++ { |
| 149 | DebugfCtx(ctx, KeyAll, "Log: %s", "Fixed String") |
| 150 | } |
| 151 | }) |
| 152 | |
| 153 | b.Run("DebugRedactTrueNotUD", func(b *testing.B) { |
| 154 | ctx := TestCtx(b) |
| 155 | RedactUserData = true |
| 156 | for i := 0; i < b.N; i++ { |
| 157 | DebugfCtx(ctx, KeyAll, "Log: %s", FakeLogger{}) |
| 158 | } |
| 159 | }) |