Skip to content

Commit

Permalink
Add some cursory benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerBrock committed May 20, 2018
1 parent b5ebcda commit 7bf832e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -2,7 +2,11 @@ Color JSON Pretty Printer for Go
================================

This package is based heavily on hokaccha/go-prettyjson but has some noticible differences:
- faster (recursive descent serializer)
- Over twice as fast (recursive descent serializer)
```
BenchmarkColorJSONMarshall-4 500000 2498 ns/op
BenchmarkPrettyJSON-4 200000 6145 ns/op
```
- more customizable (ability to have zero indent, print raw json strings, etc...)
- better defaults (less bold colors)

Expand Down
32 changes: 32 additions & 0 deletions colorjson_test.go
@@ -0,0 +1,32 @@
package colorjson_test

import "testing"
import "github.com/TylerBrock/colorjson"
import "github.com/hokaccha/go-prettyjson"

func benchmarkMarshall(i int, b *testing.B) {
simpleMap := make(map[string]interface{})
simpleMap["a"] = 1
simpleMap["b"] = "bee"

// run the Fib function b.N times
for n := 0; n < b.N; n++ {
colorjson.Marshal(simpleMap)
}
}

func benchmarkPrettyJSON(i int, b *testing.B) {
simpleMap := make(map[string]interface{})
simpleMap["a"] = 1
simpleMap["b"] = "bee"

// run the Fib function b.N times
for n := 0; n < b.N; n++ {
prettyjson.Marshal(simpleMap)
}
}

func BenchmarkMarshall(b *testing.B) { benchmarkMarshall(100, b) }
func BenchmarkMarshall1k(b *testing.B) { benchmarkMarshall(1000, b) }
func BenchmarkPrettyJSON(b *testing.B) { benchmarkPrettyJSON(100, b) }
func BenchmarkPrettyJSON1k(b *testing.B) { benchmarkPrettyJSON(1000, b) }

0 comments on commit 7bf832e

Please sign in to comment.