Skip to content

Commit 60e1ad7

Browse files
committed
Adding "bench" test cases.
This commit adds the concept of benchmarks to the JMESPath test suite. A test case may now be based on a "result", "error", or "bench". Available bench types are "parse", "interpret", or "full".
1 parent c4654c0 commit 60e1ad7

File tree

2 files changed

+131
-2
lines changed

2 files changed

+131
-2
lines changed

README.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,16 @@ Each JMESPath test case can have the following keys:
3030
against the ``given`` input.
3131
* ``error`` - The type of error that should be raised as a result of evaluating
3232
the JMESPath expression.
33+
* ``bench`` - If the case is a benchmark, ``bench`` contains the type of
34+
benchmark. Available ``bench`` types are as follows:
35+
* ``parse`` - Benchmark only the parsing of an expression.
36+
``interpret`` - Benchmark only the interpreting of an expression.
37+
``full`` - Benchmark both parsing and interepreting an expression.
3338
* ``comment`` - An optional comment containing a description of the specific
3439
test case.
3540

36-
For each test case, either ``result`` or ``error`` must be specified. Both
37-
keys cannot be present in a single test case.
41+
For each test case, either ``result``, ``error``, or ``bench`` must be
42+
specified. Both keys cannot be present in a single test case.
3843

3944
The error type (if the ``error`` key is present) indicates the type of error
4045
that an implementation should raise, but it does not indicate **when** this

tests/benchmarks.json

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
[
2+
{
3+
"given": {
4+
"long_name_for_a_field": true,
5+
"a": {
6+
"b": {
7+
"c": {
8+
"d": {
9+
"e": {
10+
"f": {
11+
"g": {
12+
"h": {
13+
"i": {
14+
"j": {
15+
"k": {
16+
"l": {
17+
"m": {
18+
"n": {
19+
"o": {
20+
"p": true
21+
}
22+
}
23+
}
24+
}
25+
}
26+
}
27+
}
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}
34+
}
35+
}
36+
},
37+
"cases": [
38+
{
39+
"comment": "simple field",
40+
"expression": "a",
41+
"bench": "full"
42+
},
43+
{
44+
"comment": "simple subexpression",
45+
"expression": "a.b",
46+
"bench": "full"
47+
},
48+
{
49+
"comment": "deep field selection",
50+
"expression": "a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s",
51+
"bench": "full"
52+
},
53+
{
54+
"comment": "simple or",
55+
"expression": "not_there || a",
56+
"bench": "full"
57+
}
58+
]
59+
},
60+
{
61+
"given": {
62+
"a":0,"b":1,"c":2,"d":3,"e":4,"f":5,"g":6,"h":7,"i":8,"j":9,"k":10,
63+
"l":11,"m":12,"n":13,"o":14,"p":15,"q":16,"r":17,"s":18,"t":19,"u":20,
64+
"v":21,"w":22,"x":23,"y":24,"z":25
65+
},
66+
"cases": [
67+
{
68+
"comment": "deep ands",
69+
"expression": "a && b && c && d && e && f && g && h && i && j && k && l && m && n && o && p && q && r && s && t && u && v && w && x && y && z",
70+
"bench": "full"
71+
},
72+
{
73+
"comment": "deep ors",
74+
"expression": "z || y || x || w || v || u || t || s || r || q || p || o || n || m || l || k || j || i || h || g || f || e || d || c || b || a",
75+
"bench": "full"
76+
},
77+
{
78+
"comment": "lots of summing",
79+
"expression": "sum(z, y, x, w, v, u, t, s, r, q, p, o, n, m, l, k, j, i, h, g, f, e, d, c, b, a)",
80+
"bench": "full"
81+
},
82+
{
83+
"comment": "lots of multi list",
84+
"expression": "[z, y, x, w, v, u, t, s, r, q, p, o, n, m, l, k, j, i, h, g, f, e, d, c, b, a]",
85+
"bench": "full"
86+
}
87+
]
88+
},
89+
{
90+
"given": {},
91+
"cases": [
92+
{
93+
"comment": "field 50",
94+
"expression": "j49.j48.j47.j46.j45.j44.j43.j42.j41.j40.j39.j38.j37.j36.j35.j34.j33.j32.j31.j30.j29.j28.j27.j26.j25.j24.j23.j22.j21.j20.j19.j18.j17.j16.j15.j14.j13.j12.j11.j10.j9.j8.j7.j6.j5.j4.j3.j2.j1.j0",
95+
"bench": "parse"
96+
},
97+
{
98+
"comment": "pipe 50",
99+
"expression": "j49|j48|j47|j46|j45|j44|j43|j42|j41|j40|j39|j38|j37|j36|j35|j34|j33|j32|j31|j30|j29|j28|j27|j26|j25|j24|j23|j22|j21|j20|j19|j18|j17|j16|j15|j14|j13|j12|j11|j10|j9|j8|j7|j6|j5|j4|j3|j2|j1|j0",
100+
"bench": "parse"
101+
},
102+
{
103+
"comment": "index 50",
104+
"expression": "[49][48][47][46][45][44][43][42][41][40][39][38][37][36][35][34][33][32][31][30][29][28][27][26][25][24][23][22][21][20][19][18][17][16][15][14][13][12][11][10][9][8][7][6][5][4][3][2][1][0]",
105+
"bench": "parse"
106+
},
107+
{
108+
"comment": "long raw string literal",
109+
"expression": "'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'",
110+
"bench": "parse"
111+
},
112+
{
113+
"comment": "deep projection 104",
114+
"expression": "a[*].b[*].c[*].d[*].e[*].f[*].g[*].h[*].i[*].j[*].k[*].l[*].m[*].n[*].o[*].p[*].q[*].r[*].s[*].t[*].u[*].v[*].w[*].x[*].y[*].z[*].a[*].b[*].c[*].d[*].e[*].f[*].g[*].h[*].i[*].j[*].k[*].l[*].m[*].n[*].o[*].p[*].q[*].r[*].s[*].t[*].u[*].v[*].w[*].x[*].y[*].z[*].a[*].b[*].c[*].d[*].e[*].f[*].g[*].h[*].i[*].j[*].k[*].l[*].m[*].n[*].o[*].p[*].q[*].r[*].s[*].t[*].u[*].v[*].w[*].x[*].y[*].z[*].a[*].b[*].c[*].d[*].e[*].f[*].g[*].h[*].i[*].j[*].k[*].l[*].m[*].n[*].o[*].p[*].q[*].r[*].s[*].t[*].u[*].v[*].w[*].x[*].y[*].z[*]",
115+
"bench": "parse"
116+
},
117+
{
118+
"comment": "filter projection",
119+
"expression": "foo[bar > baz][qux > baz]",
120+
"bench": "parse"
121+
}
122+
]
123+
}
124+
]

0 commit comments

Comments
 (0)