1//  Copyright (c) 2013 Couchbase, Inc.
2
3package collatejson
4
5import "encoding/json"
6import "reflect"
7import "testing"
8
9import qv "github.com/couchbase/query/value"
10
11func BenchmarkN1QLValue(b *testing.B) {
12	for i := 0; i < b.N; i++ {
13		qv.NewValue(testcases[0].text)
14	}
15}
16
17func BenchmarkN1QLCollateInt(b *testing.B) {
18	jsonb := []byte(`1234567890`)
19	v := qv.NewValue(jsonb)
20	b.ResetTimer()
21	for i := 0; i < b.N; i++ {
22		v.Collate(qv.NewValue(jsonb))
23	}
24}
25
26func BenchmarkN1QLCollateFloat(b *testing.B) {
27	jsonb := []byte(`1234567890.001234556`)
28	v := qv.NewValue(jsonb)
29	b.ResetTimer()
30	for i := 0; i < b.N; i++ {
31		v.Collate(qv.NewValue(jsonb))
32	}
33}
34
35func BenchmarkN1QLCollateArray(b *testing.B) {
36	jsonb := []byte(
37		`[123456789, 123456789.1234567879, "hello world", true, false, null]`)
38	v := qv.NewValue(jsonb)
39	b.ResetTimer()
40	for i := 0; i < b.N; i++ {
41		v.Collate(qv.NewValue(jsonb))
42	}
43}
44
45func BenchmarkN1QLCollateMap(b *testing.B) {
46	v := qv.NewValue(testcases[0].text)
47	b.ResetTimer()
48	for i := 0; i < b.N; i++ {
49		v.Collate(qv.NewValue(testcases[0].text))
50	}
51}
52
53func BenchmarkJSONInt(b *testing.B) {
54	var value1, value2 interface{}
55	jsonb := []byte(`1234567890`)
56	json.Unmarshal([]byte(jsonb), &value1)
57	b.ResetTimer()
58	for i := 0; i < b.N; i++ {
59		json.Unmarshal([]byte(jsonb), &value2)
60		reflect.DeepEqual(value1, value2)
61	}
62}
63
64func BenchmarkJSONFloat(b *testing.B) {
65	var value1, value2 interface{}
66	jsonb := []byte(`1234567890.001234556`)
67	json.Unmarshal([]byte(jsonb), &value1)
68	b.ResetTimer()
69	for i := 0; i < b.N; i++ {
70		json.Unmarshal([]byte(jsonb), &value2)
71		reflect.DeepEqual(value1, value2)
72	}
73}
74
75func BenchmarkJSONArray(b *testing.B) {
76	var value1, value2 interface{}
77	jsonb := []byte(
78		`[123456789, 123456789.1234567879, "hello world", true, false, null]`)
79	json.Unmarshal([]byte(jsonb), &value1)
80	b.ResetTimer()
81	for i := 0; i < b.N; i++ {
82		json.Unmarshal([]byte(jsonb), &value2)
83		reflect.DeepEqual(value1, value2)
84	}
85}
86
87func BenchmarkJSONMap(b *testing.B) {
88	var value1, value2 interface{}
89	json.Unmarshal([]byte(testcases[0].text), &value1)
90	b.ResetTimer()
91	for i := 0; i < b.N; i++ {
92		json.Unmarshal([]byte(testcases[0].text), &value2)
93		reflect.DeepEqual(value1, value2)
94	}
95}
96