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() }
func runBenchmarkGLog(b *testing.B, run func(), thread bool) { b.StopTimer() glog.Register() 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() }