Skip to content

Commit

Permalink
Use sub-benchmarks to organize benchmarks
Browse files Browse the repository at this point in the history
Use Go 1.7's fancy new sub-benchmarks feature to organize our comparative
benchmarking suite into scenarios. Within each scenario, compare all the
relevant libraries.
  • Loading branch information
Akshay Shah committed Feb 15, 2017
1 parent fc62892 commit 9ec2bd6
Show file tree
Hide file tree
Showing 10 changed files with 686 additions and 756 deletions.
52 changes: 10 additions & 42 deletions benchmarks/apex_log_bench_test.go → benchmarks/apex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,28 @@ package benchmarks

import (
"io/ioutil"
"testing"
"time"

"github.com/apex/log"
"github.com/apex/log/handlers/json"
)

func newApexLog() *log.Logger {
func newDisabledApexLog() *log.Logger {
return &log.Logger{
Handler: json.New(ioutil.Discard),
Level: log.DebugLevel,
Level: log.ErrorLevel,
}
}

func BenchmarkApexLogAddingFields(b *testing.B) {
logger := newApexLog()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.WithFields(log.Fields{
"int": 1,
"int64": int64(1),
"float": 3.0,
"string": "four!",
"bool": true,
"time": time.Unix(0, 0),
"error": errExample.Error(),
"duration": time.Second,
"user-defined type": _jane,
"another string": "done!",
}).Info("Go fast.")
}
})
func newApexLog() *log.Logger {
return &log.Logger{
Handler: json.New(ioutil.Discard),
Level: log.DebugLevel,
}
}

func BenchmarkApexLogWithAccumulatedContext(b *testing.B) {
baseLogger := newApexLog()
logger := baseLogger.WithFields(log.Fields{
func fakeApexFields() log.Fields {
return log.Fields{
"int": 1,
"int64": int64(1),
"float": 3.0,
Expand All @@ -70,21 +54,5 @@ func BenchmarkApexLogWithAccumulatedContext(b *testing.B) {
"duration": time.Second,
"user-defined type": _jane,
"another string": "done!",
})
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.Info("Go really fast.")
}
})
}

func BenchmarkApexLogWithoutFields(b *testing.B) {
logger := newApexLog()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.Info("Go fast.")
}
})
}
}
85 changes: 0 additions & 85 deletions benchmarks/kit_bench_test.go

This file was deleted.

37 changes: 4 additions & 33 deletions benchmarks/stdlib_bench_test.go → benchmarks/kit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,10 @@ package benchmarks

import (
"io/ioutil"
"log"
"testing"
"time"
)

func BenchmarkStandardLibraryWithoutFields(b *testing.B) {
logger := log.New(ioutil.Discard, "", log.LstdFlags)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.Println("Go fast.")
}
})
}
"github.com/go-kit/kit/log"
)

func BenchmarkStandardLibraryWithFormatting(b *testing.B) {
logger := log.New(ioutil.Discard, "", log.LstdFlags)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.Printf(
"Go fast. %v %v %v %s %v %v %v %v %v %s\n",
1,
int64(1),
3.0,
"four!",
true,
time.Unix(0, 0),
errExample,
time.Second,
_jane,
"done!",
)
}
})
func newKitLog() *log.Context {
return log.NewContext(log.NewJSONLogger(ioutil.Discard))
}
87 changes: 0 additions & 87 deletions benchmarks/log15_bench_test.go

This file was deleted.

40 changes: 7 additions & 33 deletions sugar_bench_test.go → benchmarks/log15_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,16 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package zap
package benchmarks

import (
"testing"
"io/ioutil"

"go.uber.org/zap/testutils"
"go.uber.org/zap/zapcore"
"gopkg.in/inconshreveable/log15.v2"
)

func withBenchedSugar(b *testing.B, f func(*SugaredLogger)) {
logger := New(zapcore.NewCore(
zapcore.NewJSONEncoder(NewProductionConfig().EncoderConfig),
&testutils.Discarder{},
DebugLevel,
)).Sugar()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
f(logger)
}
})
}

func Benchmark10FieldsSugar(b *testing.B) {
withBenchedSugar(b, func(logger *SugaredLogger) {
logger.Infow("Ten fields, passed at the log site.",
"one", 1,
"two", 2,
"three", 3,
"four", 4,
"five", 5,
"six", 6,
"seven", 7,
"eight", 8,
"nine", 9,
"ten", 10,
)
})
func newLog15() log15.Logger {
logger := log15.New()
logger.SetHandler(log15.StreamHandler(ioutil.Discard, log15.JsonFormat()))
return logger
}
Loading

0 comments on commit 9ec2bd6

Please sign in to comment.