forked from google/starlark-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.star
128 lines (106 loc) · 3.03 KB
/
benchmark.star
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
# Benchmarks of Starlark execution
# option:set
def bench_range_construction(b):
for _ in range(b.n):
range(200)
def bench_range_iteration(b):
for _ in range(b.n):
for x in range(200):
pass
# Make a 2-level call tree of 100 * 100 calls.
def bench_calling(b):
list = range(100)
def g():
for x in list:
pass
def f():
for x in list:
g()
for _ in range(b.n):
f()
# Measure overhead of calling a trivial built-in method.
emptydict = {}
range1000 = range(1000)
def bench_builtin_method(b):
for _ in range(b.n):
for _ in range1000:
emptydict.get(None)
def bench_int(b):
for _ in range(b.n):
a = 0
for _ in range1000:
a += 1
def bench_bigint(b):
for _ in range(b.n):
a = 1 << 31 # maxint32 + 1
for _ in range1000:
a += 1
def bench_gauss(b):
# Sum of arithmetic series. All results fit in int32.
for _ in range(b.n):
acc = 0
for x in range(92000):
acc += x
def bench_mix(b):
"Benchmark of a simple mix of computation (for, if, arithmetic, comprehension)."
for _ in range(b.n):
x = 0
for i in range(50):
if i:
x += 1
a = [x for x in range(i)]
largedict = {str(v): v for v in range(1000)}
def bench_dict_equal(b):
"Benchmark of dict equality operation."
for _ in range(b.n):
if largedict != largedict:
fail("invalid comparison")
largeset = set([v for v in range(1000)])
def bench_set_equal(b):
"Benchmark of set union operation."
for _ in range(b.n):
if largeset != largeset:
fail("invalid comparison")
flat = { "int": 1, "float": 0.2, "string": "string", "list": [], "bool": True, "nil": None, "tuple": (1, 2, 3) }
deep = {
"type": "int",
"value": 1,
"next": {
"type": "float",
"value": 0.2,
"next": {
"type": "string",
"value": "string",
"next": {
"type": "list",
"value": [ 1, "", True, None, (1, 2) ],
"next": {
"type": "bool",
"value": True,
"next": {
"type": "tuple",
"value": (1, 2.0, "3"),
"next": None
}
}
}
}
}
}
deep_list = [ deep for _ in range(100) ]
def bench_to_json_flat_mixed(b):
"Benchmark json.encode builtin with flat mixed input"
for _ in range(b.n):
json.encode(flat)
def bench_to_json_flat_big(b):
"Benchmark json.encode builtin with big flat integer input"
for _ in range(b.n):
json.encode(largedict)
def bench_to_json_deep(b):
"Benchmark json.encode builtin with deep input"
for _ in range(b.n):
json.encode(deep)
def bench_to_json_deep_list(b):
"Benchmark json.encode builtin with a list of deep input"
for _ in range(b.n):
json.encode(deep)