1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-15 22:50:24 +02:00
This commit is contained in:
Tao Wen
2016-12-06 13:48:03 +08:00
parent 6a46bc9513
commit c457aeaac2
2 changed files with 92 additions and 27 deletions

View File

@ -50,6 +50,17 @@ func Test_two_elements(t *testing.T) {
}
}
func Test_two_elements_cb(t *testing.T) {
iter := ParseString(`[1,2]`)
total := int64(0)
iter.ReadArrayCB(func() {
total += iter.ReadInt64()
})
if total != 3 {
t.Fatal(total)
}
}
func Test_invalid_array(t *testing.T) {
iter := ParseString(`[`)
iter.ReadArray()
@ -117,16 +128,32 @@ func Test_whitespace_before_comma(t *testing.T) {
}
}
func Benchmark_jsoniter_array(b *testing.B) {
b.ReportAllocs()
input := []byte(`[1,2,3,4,5,6,7,8,9]`)
iter := ParseBytes(input)
b.ResetTimer()
for n := 0; n < b.N; n++ {
iter := ParseString(`[1,2,3]`)
iter.Reuse(input)
for iter.ReadArray() {
iter.ReadUint64()
}
}
}
func Benchmark_jsoniter_array_cb(b *testing.B) {
b.ReportAllocs()
input := []byte(`[1,2,3,4,5,6,7,8,9]`)
iter := ParseBytes(input)
b.ResetTimer()
for n := 0; n < b.N; n++ {
iter.Reuse(input)
iter.ReadArrayCB(func() {
iter.ReadUint64()
})
}
}
func Benchmark_json_array(b *testing.B) {
for n := 0; n < b.N; n++ {
result := []interface{}{}