-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathemi.nim
149 lines (117 loc) · 3.38 KB
/
emi.nim
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import std/streams
import jason
import criterion
import eminim
template toJson(x: untyped): untyped = %* x
when not defined(danger):
{.error: "benchmark with --define:danger".}
when not defined(gcArc) and not defined(gcOrc):
{.warning: "recommend --gc:arc or --gc:orc".}
type
Some = object
goats: array[4, string]
sheep: int
ducks: float
dogs: string
cats: bool
fish: seq[int32]
#llama: (int, bool, string, float)
frogs: tuple[toads: bool, rats: string]
#geese: (int, int, int, int, int)
const
thing = Some(goats: ["black", "pigs", "pink", "horses"],
sheep: 11, ducks: 12.0,
fish: @[8'i32, 6, 7, 5, 3, 0, 9],
dogs: "woof", cats: false,
#llama: (1, true, "secret", 42.0),
#geese: (9, 0, 2, 1, 0),
frogs: (toads: true, rats: "yep"))
var cfg = newDefaultConfig()
cfg.brief = true
cfg.budget = 1.0
echo "running benchmark..."
var s = newStringStream(newStringOfCap 4000)
benchmark cfg:
proc encode_eminim_integer() {.measure.} =
s.setPosition 0
s.storeJson thing.sheep
benchmark cfg:
proc encode_jason_integer() {.measure.} =
s.setPosition 0
s.write thing.sheep.jason.string
benchmark cfg:
proc encode_eminim_bool() {.measure.} =
s.setPosition 0
s.storeJson thing.cats
benchmark cfg:
proc encode_jason_bool() {.measure.} =
s.setPosition 0
s.write thing.cats.jason.string
benchmark cfg:
proc encode_eminim_number() {.measure.} =
s.setPosition 0
s.storeJson thing.ducks
benchmark cfg:
proc encode_jason_number() {.measure.} =
s.setPosition 0
s.write thing.ducks.jason.string
benchmark cfg:
proc encode_eminim_string() {.measure.} =
s.setPosition 0
s.storeJson thing.dogs
benchmark cfg:
proc encode_jason_string() {.measure.} =
s.setPosition 0
s.write thing.dogs.jason.string
when false:
benchmark cfg:
proc encode_eminim_tuple() {.measure.} =
s.setPosition 0
s.storeJson thing.geese
benchmark cfg:
proc encode_jason_tuple() {.measure.} =
s.setPosition 0
s.write thing.geese.jason.string
benchmark cfg:
proc encode_eminim_mixed_tuple() {.measure.} =
s.setPosition 0
s.storeJson thing.llama
benchmark cfg:
proc encode_jason_mixed_tuple() {.measure.} =
s.setPosition 0
s.write thing.llama.jason.string
else:
echo "\nNOTE: anonymous tuple serialization is unsupported by eminim\n"
benchmark cfg:
proc encode_eminim_named_tuple() {.measure.} =
s.setPosition 0
s.storeJson thing.frogs
benchmark cfg:
proc encode_jason_named_tuple() {.measure.} =
s.setPosition 0
s.write thing.frogs.jason.string
benchmark cfg:
proc encode_eminim_array() {.measure.} =
s.setPosition 0
s.storeJson thing.goats
benchmark cfg:
proc encode_jason_array() {.measure.} =
s.setPosition 0
s.write thing.goats.jason.string
echo "\nNOTE: uint serialization is unsupported by eminim\n"
benchmark cfg:
proc encode_eminim_sequence() {.measure.} =
s.setPosition 0
s.storeJson thing.fish
benchmark cfg:
proc encode_jason_sequence() {.measure.} =
s.setPosition 0
s.write thing.fish.jason.string
benchmark cfg:
proc encode_eminim_large_object() {.measure.} =
s.setPosition 0
s.storeJson thing
benchmark cfg:
proc encode_jason_large_object() {.measure.} =
s.setPosition 0
s.write thing.jason.string