File: level_benchmark_test.go

package info (click to toggle)
golang-github-hashicorp-logutils 1.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 112 kB
  • sloc: makefile: 2
file content (37 lines) | stat: -rw-r--r-- 641 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package logutils

import (
	"io/ioutil"
	"testing"
)

var messages [][]byte

func init() {
	messages = [][]byte{
		[]byte("[TRACE] foo"),
		[]byte("[DEBUG] foo"),
		[]byte("[INFO] foo"),
		[]byte("[WARN] foo"),
		[]byte("[ERROR] foo"),
	}
}

func BenchmarkDiscard(b *testing.B) {
	for i := 0; i < b.N; i++ {
		ioutil.Discard.Write(messages[i%len(messages)])
	}
}

func BenchmarkLevelFilter(b *testing.B) {
	filter := &LevelFilter{
		Levels:   []LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERROR"},
		MinLevel: "WARN",
		Writer:   ioutil.Discard,
	}

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		filter.Write(messages[i%len(messages)])
	}
}