File: map_test.go

package info (click to toggle)
golang-github-ovn-org-libovsdb 0.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 1,440 kB
  • sloc: makefile: 52; sh: 14
file content (62 lines) | stat: -rw-r--r-- 2,085 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package ovsdb

import (
	"encoding/json"
	"testing"
)

func benchmarkMap(m map[string]string, b *testing.B) {
	testMap, err := NewOvsMap(m)
	if err != nil {
		b.Fatal(err)
	}
	for n := 0; n < b.N; n++ {
		_, err := json.Marshal(testMap)
		if err != nil {
			b.Fatal(err)
		}
	}
}
func BenchmarkMapMarshalJSON1(b *testing.B) { benchmarkMap(map[string]string{"foo": "bar"}, b) }
func BenchmarkMapMarshalJSON2(b *testing.B) {
	benchmarkMap(map[string]string{"foo": "bar", "baz": "quuz"}, b)
}
func BenchmarkMapMarshalJSON3(b *testing.B) {
	benchmarkMap(map[string]string{"foo": "bar", "baz": "quuz", "foobar": "foobaz"}, b)
}
func BenchmarkMapMarshalJSON5(b *testing.B) {
	benchmarkMap(map[string]string{"foo": "bar", "baz": "quuz", "foofoo": "foobar", "foobaz": "fooquuz", "barfoo": "barbar"}, b)
}
func BenchmarkMapMarshalJSON8(b *testing.B) {
	benchmarkMap(map[string]string{"foo": "bar", "baz": "quuz", "foofoo": "foobar", "foobaz": "fooquuz", "barfoo": "barbar", "barbaz": "barquuz", "bazfoo": "bazbar", "bazbaz": "bazquux"}, b)
}

func benchmarkMapUnmarshalJSON(data []byte, b *testing.B) {
	for n := 0; n < b.N; n++ {
		var m OvsMap
		err := json.Unmarshal(data, &m)
		if err != nil {
			b.Fatal(err)
		}
	}
}

func BenchmarkMapUnmarshalJSON1(b *testing.B) {
	benchmarkMapUnmarshalJSON([]byte(`[ "map", [["foo","bar"]]]`), b)
}

func BenchmarkMapUnmarshalJSON2(b *testing.B) {
	benchmarkMapUnmarshalJSON([]byte(`[ "map", [["foo","bar"],["baz", "quuz"]]]`), b)
}

func BenchmarkMapUnmarshalJSON3(b *testing.B) {
	benchmarkMapUnmarshalJSON([]byte(`[ "map", [["foo","bar"],["baz", "quuz"],["foofoo", "foobar"]]]`), b)
}

func BenchmarkMapUnmarshalJSON5(b *testing.B) {
	benchmarkMapUnmarshalJSON([]byte(`[ "map", [["foo","bar"],["baz", "quuz"],["foofoo", "foobar"],["foobaz", "fooquuz"], ["barfoo", "barbar"]]]`), b)
}

func BenchmarkMapUnmarshalJSON8(b *testing.B) {
	benchmarkMapUnmarshalJSON([]byte(`[ "map", [["foo","bar"],["baz", "quuz"],["foofoo", "foobar"],["foobaz", "fooquuz"], ["barfoo", "barbar"],["barbaz", "barquux"],["bazfoo", "bazbar"], ["bazbaz", "bazquux"]]]`), b)
}