mirror of
https://github.com/taigrr/log-socket
synced 2026-03-20 18:22:24 -07:00
Compare commits
1 Commits
cd/6-add-b
...
burrow/6-a
| Author | SHA1 | Date | |
|---|---|---|---|
| 4d74b0a950 |
171
log/bench_test.go
Normal file
171
log/bench_test.go
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
const benchNS = "bench-isolated-ns"
|
||||||
|
|
||||||
|
// benchClient creates a client with a continuous drain goroutine.
|
||||||
|
// Returns the client and a stop function to call after b.StopTimer().
|
||||||
|
func benchClient(ns string) (*Client, func()) {
|
||||||
|
c := CreateClient(ns)
|
||||||
|
c.SetLogLevel(LTrace)
|
||||||
|
done := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
return
|
||||||
|
case <-c.writer:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return c, func() {
|
||||||
|
close(done)
|
||||||
|
c.Destroy()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BenchmarkCreateClient measures client creation overhead.
|
||||||
|
func BenchmarkCreateClient(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
c := CreateClient("bench")
|
||||||
|
c.Destroy()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BenchmarkTrace benchmarks Logger.Trace.
|
||||||
|
func BenchmarkTrace(b *testing.B) {
|
||||||
|
l := NewLogger(benchNS)
|
||||||
|
_, stop := benchClient(benchNS)
|
||||||
|
defer stop()
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
l.Trace("benchmark trace message")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BenchmarkTracef benchmarks formatted Logger.Tracef.
|
||||||
|
func BenchmarkTracef(b *testing.B) {
|
||||||
|
l := NewLogger(benchNS)
|
||||||
|
_, stop := benchClient(benchNS)
|
||||||
|
defer stop()
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
l.Tracef("benchmark trace message %d", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BenchmarkDebug benchmarks Logger.Debug.
|
||||||
|
func BenchmarkDebug(b *testing.B) {
|
||||||
|
l := NewLogger(benchNS)
|
||||||
|
_, stop := benchClient(benchNS)
|
||||||
|
defer stop()
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
l.Debug("benchmark debug message")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BenchmarkInfo benchmarks Logger.Info.
|
||||||
|
func BenchmarkInfo(b *testing.B) {
|
||||||
|
l := NewLogger(benchNS)
|
||||||
|
_, stop := benchClient(benchNS)
|
||||||
|
defer stop()
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
l.Info("benchmark info message")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BenchmarkInfof benchmarks Logger.Infof with formatting.
|
||||||
|
func BenchmarkInfof(b *testing.B) {
|
||||||
|
l := NewLogger(benchNS)
|
||||||
|
_, stop := benchClient(benchNS)
|
||||||
|
defer stop()
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
l.Infof("user %s performed action %d", "testuser", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BenchmarkWarn benchmarks Logger.Warn.
|
||||||
|
func BenchmarkWarn(b *testing.B) {
|
||||||
|
l := NewLogger(benchNS)
|
||||||
|
_, stop := benchClient(benchNS)
|
||||||
|
defer stop()
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
l.Warn("benchmark warn message")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BenchmarkError benchmarks Logger.Error.
|
||||||
|
func BenchmarkError(b *testing.B) {
|
||||||
|
l := NewLogger(benchNS)
|
||||||
|
_, stop := benchClient(benchNS)
|
||||||
|
defer stop()
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
l.Error("benchmark error message")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BenchmarkMultipleClients measures fan-out to multiple consumers.
|
||||||
|
func BenchmarkMultipleClients(b *testing.B) {
|
||||||
|
const numClients = 5
|
||||||
|
l := NewLogger(benchNS)
|
||||||
|
stops := make([]func(), numClients)
|
||||||
|
for i := range stops {
|
||||||
|
_, stops[i] = benchClient(benchNS)
|
||||||
|
}
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
l.Info("benchmark multi-client")
|
||||||
|
}
|
||||||
|
b.StopTimer()
|
||||||
|
for _, stop := range stops {
|
||||||
|
stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BenchmarkParallelInfo benchmarks concurrent Info calls from multiple goroutines.
|
||||||
|
func BenchmarkParallelInfo(b *testing.B) {
|
||||||
|
l := NewLogger(benchNS)
|
||||||
|
_, stop := benchClient(benchNS)
|
||||||
|
defer stop()
|
||||||
|
b.ResetTimer()
|
||||||
|
b.RunParallel(func(pb *testing.PB) {
|
||||||
|
for pb.Next() {
|
||||||
|
l.Info("parallel benchmark info")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// BenchmarkNamespaceFiltering benchmarks logging when the consumer
|
||||||
|
// filters by a different namespace (messages are not delivered).
|
||||||
|
func BenchmarkNamespaceFiltering(b *testing.B) {
|
||||||
|
l := NewLogger(benchNS)
|
||||||
|
_, stop := benchClient("completely-different-ns")
|
||||||
|
defer stop()
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
l.Info("filtered out message")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BenchmarkFileInfo measures the cost of runtime.Caller for file info.
|
||||||
|
func BenchmarkFileInfo(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
fileInfo(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BenchmarkEntryCreation measures raw fmt.Sprint overhead (baseline).
|
||||||
|
func BenchmarkEntryCreation(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
_ = fmt.Sprint("benchmark message ", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,389 +0,0 @@
|
|||||||
package log
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
// drainClient continuously reads from a client to prevent blocking.
|
|
||||||
// Returns a function to stop draining and wait for completion.
|
|
||||||
func drainClient(c *Client) func() {
|
|
||||||
done := make(chan struct{})
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
return
|
|
||||||
case <-c.writer:
|
|
||||||
// Drain entries
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
return func() { close(done) }
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// Serial Benchmarks - Single Log Levels
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
func BenchmarkTrace(b *testing.B) {
|
|
||||||
c := CreateClient(DefaultNamespace)
|
|
||||||
c.SetLogLevel(LTrace)
|
|
||||||
stop := drainClient(c)
|
|
||||||
defer stop()
|
|
||||||
defer c.Destroy()
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
Trace("benchmark message")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkDebug(b *testing.B) {
|
|
||||||
c := CreateClient(DefaultNamespace)
|
|
||||||
c.SetLogLevel(LDebug)
|
|
||||||
stop := drainClient(c)
|
|
||||||
defer stop()
|
|
||||||
defer c.Destroy()
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
Debug("benchmark message")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkInfo(b *testing.B) {
|
|
||||||
c := CreateClient(DefaultNamespace)
|
|
||||||
c.SetLogLevel(LInfo)
|
|
||||||
stop := drainClient(c)
|
|
||||||
defer stop()
|
|
||||||
defer c.Destroy()
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
Info("benchmark message")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkNotice(b *testing.B) {
|
|
||||||
c := CreateClient(DefaultNamespace)
|
|
||||||
c.SetLogLevel(LNotice)
|
|
||||||
stop := drainClient(c)
|
|
||||||
defer stop()
|
|
||||||
defer c.Destroy()
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
Notice("benchmark message")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkWarn(b *testing.B) {
|
|
||||||
c := CreateClient(DefaultNamespace)
|
|
||||||
c.SetLogLevel(LWarn)
|
|
||||||
stop := drainClient(c)
|
|
||||||
defer stop()
|
|
||||||
defer c.Destroy()
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
Warn("benchmark message")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkError(b *testing.B) {
|
|
||||||
c := CreateClient(DefaultNamespace)
|
|
||||||
c.SetLogLevel(LError)
|
|
||||||
stop := drainClient(c)
|
|
||||||
defer stop()
|
|
||||||
defer c.Destroy()
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
Error("benchmark message")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// Formatted Logging Benchmarks
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
func BenchmarkDebugf(b *testing.B) {
|
|
||||||
c := CreateClient(DefaultNamespace)
|
|
||||||
c.SetLogLevel(LDebug)
|
|
||||||
stop := drainClient(c)
|
|
||||||
defer stop()
|
|
||||||
defer c.Destroy()
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
Debugf("benchmark message %d with %s", i, "formatting")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkInfof(b *testing.B) {
|
|
||||||
c := CreateClient(DefaultNamespace)
|
|
||||||
c.SetLogLevel(LInfo)
|
|
||||||
stop := drainClient(c)
|
|
||||||
defer stop()
|
|
||||||
defer c.Destroy()
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
Infof("benchmark message %d with %s", i, "formatting")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkErrorf(b *testing.B) {
|
|
||||||
c := CreateClient(DefaultNamespace)
|
|
||||||
c.SetLogLevel(LError)
|
|
||||||
stop := drainClient(c)
|
|
||||||
defer stop()
|
|
||||||
defer c.Destroy()
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
Errorf("benchmark message %d with %s", i, "formatting")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// Parallel Benchmarks
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
func BenchmarkDebugParallel(b *testing.B) {
|
|
||||||
c := CreateClient(DefaultNamespace)
|
|
||||||
c.SetLogLevel(LDebug)
|
|
||||||
stop := drainClient(c)
|
|
||||||
defer stop()
|
|
||||||
defer c.Destroy()
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
b.RunParallel(func(pb *testing.PB) {
|
|
||||||
for pb.Next() {
|
|
||||||
Debug("parallel benchmark message")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkInfoParallel(b *testing.B) {
|
|
||||||
c := CreateClient(DefaultNamespace)
|
|
||||||
c.SetLogLevel(LInfo)
|
|
||||||
stop := drainClient(c)
|
|
||||||
defer stop()
|
|
||||||
defer c.Destroy()
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
b.RunParallel(func(pb *testing.PB) {
|
|
||||||
for pb.Next() {
|
|
||||||
Info("parallel benchmark message")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkInfofParallel(b *testing.B) {
|
|
||||||
c := CreateClient(DefaultNamespace)
|
|
||||||
c.SetLogLevel(LInfo)
|
|
||||||
stop := drainClient(c)
|
|
||||||
defer stop()
|
|
||||||
defer c.Destroy()
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
b.RunParallel(func(pb *testing.PB) {
|
|
||||||
counter := 0
|
|
||||||
for pb.Next() {
|
|
||||||
Infof("parallel benchmark message %d", counter)
|
|
||||||
counter++
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// Logger Instance Benchmarks (Namespaced Logging)
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
func BenchmarkLoggerInfo(b *testing.B) {
|
|
||||||
logger := NewLogger("benchmark")
|
|
||||||
c := CreateClient("benchmark")
|
|
||||||
c.SetLogLevel(LInfo)
|
|
||||||
stop := drainClient(c)
|
|
||||||
defer stop()
|
|
||||||
defer c.Destroy()
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
logger.Info("benchmark message")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkLoggerInfof(b *testing.B) {
|
|
||||||
logger := NewLogger("benchmark")
|
|
||||||
c := CreateClient("benchmark")
|
|
||||||
c.SetLogLevel(LInfo)
|
|
||||||
stop := drainClient(c)
|
|
||||||
defer stop()
|
|
||||||
defer c.Destroy()
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
logger.Infof("benchmark message %d", i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkLoggerDebugParallel(b *testing.B) {
|
|
||||||
logger := NewLogger("benchmark")
|
|
||||||
c := CreateClient("benchmark")
|
|
||||||
c.SetLogLevel(LDebug)
|
|
||||||
stop := drainClient(c)
|
|
||||||
defer stop()
|
|
||||||
defer c.Destroy()
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
b.RunParallel(func(pb *testing.PB) {
|
|
||||||
for pb.Next() {
|
|
||||||
logger.Debug("parallel benchmark message")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// Multiple Client Benchmarks
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
func BenchmarkMultipleClients(b *testing.B) {
|
|
||||||
const numClients = 5
|
|
||||||
var clients []*Client
|
|
||||||
var stopFuncs []func()
|
|
||||||
|
|
||||||
for i := 0; i < numClients; i++ {
|
|
||||||
c := CreateClient(DefaultNamespace)
|
|
||||||
c.SetLogLevel(LInfo)
|
|
||||||
stop := drainClient(c)
|
|
||||||
clients = append(clients, c)
|
|
||||||
stopFuncs = append(stopFuncs, stop)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
for i, c := range clients {
|
|
||||||
stopFuncs[i]()
|
|
||||||
c.Destroy()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
Info("benchmark message to multiple clients")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkMultipleNamespaces(b *testing.B) {
|
|
||||||
namespaces := []string{"auth", "db", "api", "cache", "queue"}
|
|
||||||
var loggers []*Logger
|
|
||||||
var clients []*Client
|
|
||||||
var stopFuncs []func()
|
|
||||||
|
|
||||||
for _, ns := range namespaces {
|
|
||||||
loggers = append(loggers, NewLogger(ns))
|
|
||||||
c := CreateClient(ns)
|
|
||||||
c.SetLogLevel(LInfo)
|
|
||||||
stop := drainClient(c)
|
|
||||||
clients = append(clients, c)
|
|
||||||
stopFuncs = append(stopFuncs, stop)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
for i, c := range clients {
|
|
||||||
stopFuncs[i]()
|
|
||||||
c.Destroy()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
loggers[i%len(loggers)].Info("benchmark message")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// With Synchronous Client Consumption (Legacy Pattern)
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// BenchmarkDebugWithSyncConsumer measures the overhead of synchronous consumption
|
|
||||||
// using the Get() method, processing one message at a time.
|
|
||||||
func BenchmarkDebugWithSyncConsumer(b *testing.B) {
|
|
||||||
c := CreateClient(DefaultNamespace)
|
|
||||||
c.SetLogLevel(LDebug)
|
|
||||||
stop := drainClient(c)
|
|
||||||
defer stop()
|
|
||||||
defer c.Destroy()
|
|
||||||
|
|
||||||
// This benchmark measures just the logging side with async draining.
|
|
||||||
// For sync consumption patterns, see the TestOrder test.
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
Debug("benchmark message")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// Comparison Benchmarks (Different Message Sizes)
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
func BenchmarkInfoShortMessage(b *testing.B) {
|
|
||||||
c := CreateClient(DefaultNamespace)
|
|
||||||
c.SetLogLevel(LInfo)
|
|
||||||
stop := drainClient(c)
|
|
||||||
defer stop()
|
|
||||||
defer c.Destroy()
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
Info("ok")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkInfoMediumMessage(b *testing.B) {
|
|
||||||
c := CreateClient(DefaultNamespace)
|
|
||||||
c.SetLogLevel(LInfo)
|
|
||||||
stop := drainClient(c)
|
|
||||||
defer stop()
|
|
||||||
defer c.Destroy()
|
|
||||||
|
|
||||||
msg := "This is a medium-length log message for benchmarking purposes"
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
Info(msg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkInfoLongMessage(b *testing.B) {
|
|
||||||
c := CreateClient(DefaultNamespace)
|
|
||||||
c.SetLogLevel(LInfo)
|
|
||||||
stop := drainClient(c)
|
|
||||||
defer stop()
|
|
||||||
defer c.Destroy()
|
|
||||||
|
|
||||||
msg := "This is a much longer log message that simulates real-world logging scenarios where developers tend to include more context about what the application is doing, including variable values, request IDs, and other debugging information that can be quite verbose"
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
Info(msg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// Overhead Benchmarks (Level Filtering)
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
func BenchmarkDebugFilteredByLevel(b *testing.B) {
|
|
||||||
// No client with Debug level, so Debug logs won't be consumed
|
|
||||||
// This measures the overhead of creating log entries that get filtered
|
|
||||||
c := CreateClient(DefaultNamespace)
|
|
||||||
c.SetLogLevel(LError) // Only Error and above
|
|
||||||
stop := drainClient(c)
|
|
||||||
defer stop()
|
|
||||||
defer c.Destroy()
|
|
||||||
|
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
Debug("this message will be filtered")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,7 @@ package log
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -36,6 +37,21 @@ func TestSetLogLevel(t *testing.T) {
|
|||||||
c.Destroy()
|
c.Destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkDebugSerial(b *testing.B) {
|
||||||
|
c := CreateClient("test")
|
||||||
|
var x sync.WaitGroup
|
||||||
|
x.Add(b.N)
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
Debug(i)
|
||||||
|
go func() {
|
||||||
|
c.Get()
|
||||||
|
x.Done()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
x.Wait()
|
||||||
|
c.Destroy()
|
||||||
|
}
|
||||||
|
|
||||||
// Trace ensure logs come out in the right order
|
// Trace ensure logs come out in the right order
|
||||||
func TestOrder(t *testing.T) {
|
func TestOrder(t *testing.T) {
|
||||||
testString := "Testing trace: "
|
testString := "Testing trace: "
|
||||||
|
|||||||
Reference in New Issue
Block a user