...
1 package colorjson_test
2
3 import "testing"
4 import "github.com/TylerBrock/colorjson"
5 import "github.com/hokaccha/go-prettyjson"
6
7 func benchmarkMarshall(i int, b *testing.B) {
8 simpleMap := make(map[string]interface{})
9 simpleMap["a"] = 1
10 simpleMap["b"] = "bee"
11 simpleMap["c"] = [3]float64{1, 2, 3}
12 simpleMap["d"] = [3]string{"one", "two", "three"}
13
14
15 for n := 0; n < b.N; n++ {
16 colorjson.Marshal(simpleMap)
17 }
18 }
19
20 func benchmarkPrettyJSON(i int, b *testing.B) {
21 simpleMap := make(map[string]interface{})
22 simpleMap["a"] = 1
23 simpleMap["b"] = "bee"
24 simpleMap["c"] = [3]float64{1, 2, 3}
25 simpleMap["d"] = [3]string{"one", "two", "three"}
26
27
28 for n := 0; n < b.N; n++ {
29 prettyjson.Marshal(simpleMap)
30 }
31 }
32
33 func BenchmarkMarshall(b *testing.B) { benchmarkMarshall(100, b) }
34 func BenchmarkMarshall1k(b *testing.B) { benchmarkMarshall(1000, b) }
35 func BenchmarkPrettyJSON(b *testing.B) { benchmarkPrettyJSON(100, b) }
36 func BenchmarkPrettyJSON1k(b *testing.B) { benchmarkPrettyJSON(1000, b) }
37
View as plain text