Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
fix: fix benchmark bug
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkgos committed Apr 16, 2024
1 parent 773974f commit 7cc6165
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
26 changes: 21 additions & 5 deletions benchmark_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@ func Benchmark_Json_NativeSugar(b *testing.B) {
}

func Benchmark_Json_SugarKeyValuePair(b *testing.B) {
b.ReportAllocs()
b.StopTimer()
logger := newDiscardLogger(log.FormatJson)
ctx := context.Background()
b.StartTimer()
for i := 0; i < b.N; i++ {
logger.InfowContext(ctx,
"success",
"name", "jack",
"age", 18,
dfltCtx(ctx),
)
}
}

func Benchmark_Json_SugarKeyValuePairFields(b *testing.B) {
b.ReportAllocs()
b.StopTimer()
logger := newDiscardLogger(log.FormatJson)
Expand All @@ -123,7 +139,7 @@ func Benchmark_Json_SugarKeyValuePair(b *testing.B) {
}
}

func Benchmark_Json_SugarKeyValuePair_Use_Hook(b *testing.B) {
func Benchmark_Json_SugarKeyValuePairFields_Use_Hook(b *testing.B) {
b.ReportAllocs()
b.StopTimer()
logger := newDiscardLogger(log.FormatJson)
Expand All @@ -139,7 +155,7 @@ func Benchmark_Json_SugarKeyValuePair_Use_Hook(b *testing.B) {
}
}

func Benchmark_Json_SugarKeyValuePair_Use_WithFields(b *testing.B) {
func Benchmark_Json_SugarKeyValuePairFields_Use_WithFields(b *testing.B) {
b.ReportAllocs()
b.StopTimer()
logger := newDiscardLogger(log.FormatJson)
Expand All @@ -154,7 +170,7 @@ func Benchmark_Json_SugarKeyValuePair_Use_WithFields(b *testing.B) {
}
}

func Benchmark_Json_SugarKeyValuePair_Use_WithFields_Hook(b *testing.B) {
func Benchmark_Json_SugarKeyValuePairFields_Use_WithFields_Hook(b *testing.B) {
b.ReportAllocs()
b.StopTimer()
logger := newDiscardLogger(log.FormatJson)
Expand All @@ -169,7 +185,7 @@ func Benchmark_Json_SugarKeyValuePair_Use_WithFields_Hook(b *testing.B) {
}
}

func Benchmark_Json_SugarKeyValuePair_Use_WithValuer(b *testing.B) {
func Benchmark_Json_SugarKeyValuePairFields_Use_WithValuer(b *testing.B) {
b.ReportAllocs()
b.StopTimer()
logger := newDiscardLogger(log.FormatJson)
Expand All @@ -184,7 +200,7 @@ func Benchmark_Json_SugarKeyValuePair_Use_WithValuer(b *testing.B) {
}
}

func Benchmark_Json_SugarKeyValuePair_Use_WithValuer_Hook(b *testing.B) {
func Benchmark_Json_SugarKeyValuePairFields_Use_WithValuer_Hook(b *testing.B) {
b.ReportAllocs()
b.StopTimer()
logger := newDiscardLogger(log.FormatJson)
Expand Down
26 changes: 21 additions & 5 deletions benchmark_text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ func Benchmark_Text_NativeSugar(b *testing.B) {
}

func Benchmark_Text_SugarKeyValuePair(b *testing.B) {
b.ReportAllocs()
b.StopTimer()
logger := newDiscardLogger(log.FormatConsole)
ctx := context.Background()
b.StartTimer()
for i := 0; i < b.N; i++ {
logger.InfowContext(ctx,
"success",
"name", "jack",
"age", 18,
dfltCtx(ctx),
)
}
}

func Benchmark_Text_SugarKeyValuePairFields(b *testing.B) {
b.ReportAllocs()
b.StopTimer()
logger := newDiscardLogger(log.FormatConsole)
Expand All @@ -98,7 +114,7 @@ func Benchmark_Text_SugarKeyValuePair(b *testing.B) {
}
}

func Benchmark_Text_SugarKeyValuePair_Use_Hook(b *testing.B) {
func Benchmark_Text_SugarKeyValuePairFields_Use_Hook(b *testing.B) {
b.ReportAllocs()
b.StopTimer()
logger := newDiscardLogger(log.FormatConsole)
Expand All @@ -114,7 +130,7 @@ func Benchmark_Text_SugarKeyValuePair_Use_Hook(b *testing.B) {
}
}

func Benchmark_Text_SugarKeyValuePair_Use_WithFields(b *testing.B) {
func Benchmark_Text_SugarKeyValuePairFields_Use_WithFields(b *testing.B) {
b.ReportAllocs()
b.StopTimer()
logger := newDiscardLogger(log.FormatConsole)
Expand All @@ -129,7 +145,7 @@ func Benchmark_Text_SugarKeyValuePair_Use_WithFields(b *testing.B) {
}
}

func Benchmark_Text_SugarKeyValuePair_Use_WithFields_Hook(b *testing.B) {
func Benchmark_Text_SugarKeyValuePairFields_Use_WithFields_Hook(b *testing.B) {
b.ReportAllocs()
b.StopTimer()
logger := newDiscardLogger(log.FormatConsole)
Expand All @@ -144,7 +160,7 @@ func Benchmark_Text_SugarKeyValuePair_Use_WithFields_Hook(b *testing.B) {
}
}

func Benchmark_Text_SugarKeyValuePair_Use_WithValuer(b *testing.B) {
func Benchmark_Text_SugarKeyValuePairFields_Use_WithValuer(b *testing.B) {
b.ReportAllocs()
b.StopTimer()
logger := newDiscardLogger(log.FormatConsole)
Expand All @@ -159,7 +175,7 @@ func Benchmark_Text_SugarKeyValuePair_Use_WithValuer(b *testing.B) {
}
}

func Benchmark_Text_SugarKeyValuePair_Use_WithValuer_Hook(b *testing.B) {
func Benchmark_Text_SugarKeyValuePairFields_Use_WithValuer_Hook(b *testing.B) {
b.ReportAllocs()
b.StopTimer()
logger := newDiscardLogger(log.FormatConsole)
Expand Down

0 comments on commit 7cc6165

Please sign in to comment.