Skip to content

Commit

Permalink
add async writer benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
phuslu committed Jun 3, 2024
1 parent c60d558 commit 93e69ea
Showing 1 changed file with 46 additions and 5 deletions.
51 changes: 46 additions & 5 deletions async_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,60 @@ func TestAsyncWriterSmall(t *testing.T) {
}
}

func BenchmarkAsyncWriter(b *testing.B) {
func BenchmarkSyncFileWriter(b *testing.B) {
logger := Logger{
Writer: &FileWriter{
Filename: "sync_file_test.log",
},
}
defer logger.Writer.(io.Closer).Close()

b.ReportAllocs()
b.ResetTimer()
b.RunParallel(func(b *testing.PB) {
for b.Next() {
logger.Info().Msg("hello file writer")
}
})
}

func BenchmarkAsyncFileWriter(b *testing.B) {
logger := Logger{
Writer: &AsyncWriter{
ChannelSize: 4096,
Writer: &FileWriter{
Filename: "async_file_test.log",
},
},
}
defer logger.Writer.(io.Closer).Close()

b.ReportAllocs()
b.ResetTimer()
b.RunParallel(func(b *testing.PB) {
for b.Next() {
logger.Info().Msg("hello file writer")
}
})
}

func BenchmarkAsyncFileWriterWriteV(b *testing.B) {
logger := Logger{
Writer: &AsyncWriter{
ChannelSize: 100,
Writer: IOWriter{io.Discard},
ChannelSize: 4096,
WritevEnabled: true,
Writer: &FileWriter{
Filename: "async_file_test2.log",
},
},
}
b.SetParallelism(1000)
defer logger.Writer.(io.Closer).Close()

b.ReportAllocs()
b.ResetTimer()
b.RunParallel(func(b *testing.PB) {
for b.Next() {
logger.Info().Msg("hello async writer")
logger.Info().Msg("hello file writer")
}
})
}

0 comments on commit 93e69ea

Please sign in to comment.