Beispiel #1
0
func runBenchmarkLogrus(b *testing.B, run func(), thread bool) {
	b.StopTimer()
	tempDir, err := ioutil.TempDir("", "protolog")
	require.NoError(b, err)
	file, err := os.Create(filepath.Join(tempDir, "log.out"))
	require.NoError(b, err)
	logrus.SetPusherOptions(
		logrus.PusherOptions{
			Out: file,
			Formatter: &stdlogrus.TextFormatter{
				ForceColors: true,
			},
		},
	)
	b.StartTimer()
	if thread {
		var wg sync.WaitGroup
		wg.Add(b.N)
		for i := 0; i < b.N; i++ {
			go func() {
				run()
				wg.Done()
			}()
		}
		wg.Wait()
	} else {
		for i := 0; i < b.N; i++ {
			run()
		}
	}
	_ = protolog.Flush()
	b.StopTimer()
	_ = os.RemoveAll(tempDir)
	b.StartTimer()
}
Beispiel #2
0
func init() {
	logrus.SetPusherOptions(
		logrus.PusherOptions{
			Formatter: &stdlogrus.TextFormatter{
				ForceColors: true,
			},
		},
	)
}