Skip to content

Commit a1bcd6b

Browse files
sbarzowskisparkprime
authored andcommitted
Add benchmarks
One of the benchmarks is generated. It may be useful to do that sometimes, especially with parser-oriented benchmarks. Jsonnet is used to generate the 5th benchmark (dogfooding!). *.gen.jsonnet files are added to local .gitignore so that we don't keep big benchmarks in the repo. Run ./regen_benchmarks.sh to generate them.
1 parent 483bdf3 commit a1bcd6b

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

benchmarks/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.gen.jsonnet

benchmarks/bench.04.jsonnet

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
std.foldl(function(e, res) e + res, std.makeArray(20000, function(i) 'aaaaa'), '')

benchmarks/bench.07.jsonnet

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
local f2(f) = function(x) f(f(x));
2+
local id(x) = x;
3+
4+
local slowId = std.makeArray(20, function(i) if i == 0 then id else f2(slowId[i - 1]));
5+
6+
slowId[15](42)

benchmarks/gen_big_object.jsonnet

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
local n = 2000;
2+
3+
local objLocal(name, body) = 'local ' + name + ' = ' + body + ',';
4+
local objField(name, body) = name + ': ' + body + ',';
5+
6+
local allLocals =
7+
std.makeArray(n, function(i) objLocal('l' + i, '1'));
8+
9+
local allFields =
10+
std.makeArray(n, function(i) objField('f' + i, '2'));
11+
12+
local indent = ' ';
13+
local indentAndSeparate(s) = indent + s + '\n';
14+
15+
local objContents = std.map(indentAndSeparate, allLocals + allFields);
16+
17+
local objectBody = std.join('', objContents);
18+
'{\n' + objectBody + '}\n'

benchmarks/regen_benchmarks.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -x
5+
6+
../jsonnet -S gen_big_object.jsonnet > bench.05.gen.jsonnet
7+
8+
for i in *.gen.jsonnet; do
9+
../jsonnet fmt -i "$i"
10+
done

0 commit comments

Comments
 (0)