Skip to content

Commit a428212

Browse files
authored
Merge pull request #78 from a8m/bench/add-djson
bench: add a8m/djson as a compared library #75
2 parents 69062e2 + 5193950 commit a428212

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

benchmark/benchmark_large_payload_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
// "github.com/Jeffail/gabs"
1212
// "github.com/bitly/go-simplejson"
1313
"encoding/json"
14+
"github.com/a8m/djson"
1415
jlexer "github.com/mailru/easyjson/jlexer"
1516
"github.com/pquerna/ffjson/ffjson"
1617
// "github.com/antonholmquist/jason"
@@ -109,3 +110,22 @@ func BenchmarkEasyJsonLarge(b *testing.B) {
109110
}
110111
}
111112
}
113+
114+
/*
115+
github.com/a8m/djson
116+
*/
117+
func BenchmarkDjsonLarge(b *testing.B) {
118+
for i := 0; i < b.N; i++ {
119+
m, _ := djson.DecodeObject(largeFixture)
120+
users := m["users"].([]interface{})
121+
for _, u := range users {
122+
nothing(u.(map[string]interface{})["username"].(string))
123+
}
124+
125+
topics := m["topics"].(map[string]interface{})["topics"].([]interface{})
126+
for _, t := range topics {
127+
tI := t.(map[string]interface{})
128+
nothing(tI["id"].(float64), tI["slug"].(string))
129+
}
130+
}
131+
}

benchmark/benchmark_medium_payload_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package benchmark
77
import (
88
"encoding/json"
99
"github.com/Jeffail/gabs"
10+
"github.com/a8m/djson"
1011
"github.com/antonholmquist/jason"
1112
"github.com/bitly/go-simplejson"
1213
"github.com/buger/jsonparser"
@@ -282,6 +283,26 @@ func BenchmarkUjsonMedium(b *testing.B) {
282283
}
283284
}
284285

286+
/*
287+
github.com/a8m/djson
288+
*/
289+
func BenchmarkDjsonMedium(b *testing.B) {
290+
for i := 0; i < b.N; i++ {
291+
m, _ := djson.DecodeObject(mediumFixture)
292+
person := m["person"].(map[string]interface{})
293+
name := person["name"].(map[string]interface{})
294+
github := person["github"].(map[string]interface{})
295+
company := m["company"]
296+
gravatar := person["gravatar"].(map[string]interface{})
297+
avatars := gravatar["avatars"].([]interface{})
298+
299+
nothing(name["fullName"].(string), github["followers"].(float64), company)
300+
for _, a := range avatars {
301+
nothing(a.(map[string]interface{})["url"])
302+
}
303+
}
304+
}
305+
285306
/*
286307
github.com/ugorji/go/codec
287308
*/

benchmark/benchmark_small_payload_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package benchmark
77
import (
88
"encoding/json"
99
"github.com/Jeffail/gabs"
10+
"github.com/a8m/djson"
1011
"github.com/antonholmquist/jason"
1112
"github.com/bitly/go-simplejson"
1213
"github.com/buger/jsonparser"
@@ -218,7 +219,6 @@ func BenchmarkJasonSmall(b *testing.B) {
218219
/*
219220
github.com/mreiferson/go-ujson
220221
*/
221-
222222
func BenchmarkUjsonSmall(b *testing.B) {
223223
for i := 0; i < b.N; i++ {
224224
json, _ := ujson.NewFromBytes(smallFixture)
@@ -232,6 +232,16 @@ func BenchmarkUjsonSmall(b *testing.B) {
232232
}
233233
}
234234

235+
/*
236+
github.com/a8m/djson
237+
*/
238+
func BenchmarkDjsonSmall(b *testing.B) {
239+
for i := 0; i < b.N; i++ {
240+
m, _ := djson.DecodeObject(smallFixture)
241+
nothing(m["uuid"].(string), m["tz"].(float64), m["ua"].(string), m["st"].(float64))
242+
}
243+
}
244+
235245
/*
236246
github.com/ugorji/go/codec
237247
*/

0 commit comments

Comments
 (0)