Skip to content

Commit 5bf3603

Browse files
committed
Merge branch 'more-perf' into develop
* more-perf: Add more perf tests Add deeply nested projection perf test Move cases into their own directory
2 parents ca7250d + 9a3213d commit 5bf3603

File tree

7 files changed

+41
-6
lines changed

7 files changed

+41
-6
lines changed
File renamed without changes.

perf/deep_hierarchy.json renamed to perf/cases/deep_hierarchy.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
{
1212
"name": "deep_nesting_50",
1313
"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",
14-
"result": []
14+
"result": {}
1515
},
1616
{
1717
"name": "deep_nesting_50_pipe",

perf/cases/deep_projection.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"description": "Deep projections",
3+
"given":
4+
{"a": []},
5+
"cases": [
6+
{
7+
"name": "deep_projection_104",
8+
"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[*]",
9+
"result": []
10+
}
11+
]
12+
}
13+

perf/cases/functions.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"description": "Deep projections",
3+
"given":
4+
[749, 222, 102, 148, 869, 848, 326, 644, 402, 150, 361, 827, 741, 60, 842, 943, 214, 519, 134, 866, 621, 851, 59, 580, 760, 576, 951, 989, 266, 259, 809, 643, 292, 731, 129, 970, 589, 430, 690, 715, 901, 491, 276, 88, 738, 282, 547, 349, 236, 879, 403, 557, 554, 23, 649, 720, 531, 2, 601, 152, 530, 477, 568, 122, 811, 75, 181, 203, 683, 152, 794, 155, 54, 314, 957, 468, 740, 532, 504, 806, 927, 827, 840, 100, 519, 357, 536, 398, 417, 543, 599, 383, 144, 772, 988, 184, 118, 921, 497, 193, 320, 919, 583, 346, 575, 143, 866, 907, 570, 255, 539, 164, 764, 256, 315, 305, 960, 587, 804, 577, 667, 869, 563, 956, 677, 469, 934, 52, 323, 933, 398, 305, 138, 133, 443, 419, 717, 838, 287, 177, 192, 210, 892, 319, 470, 76, 643, 737, 135, 425, 586, 882, 844, 113, 268, 323, 938, 569, 374, 295, 648, 27, 703, 530, 667, 118, 176, 972, 611, 60, 47, 19, 500, 344, 332, 452, 647, 388, 188, 235, 151, 353, 219, 766, 626, 885, 456, 182, 363, 617, 236, 285, 152, 87, 666, 429, 599, 762, 13, 778, 634, 43, 199, 361, 300, 370, 957, 488, 359, 354, 972, 368, 482, 88, 766, 709, 804, 637, 368, 950, 752, 932, 638, 291, 177, 739, 740, 357, 928, 964, 621, 472, 813, 36, 271, 642, 3, 771, 397, 670, 324, 244, 827, 194, 693, 846, 351, 668, 911, 600, 682, 735, 26, 876, 581, 915, 184, 263, 857, 960, 5, 523, 932, 694, 457, 739, 897, 28, 794, 885, 77, 768, 39, 763, 748, 792, 60, 582, 667, 909, 820, 898, 569, 252, 583, 237, 677, 613, 914, 956, 541, 297, 853, 581, 118, 888, 368, 156, 582, 183],
5+
"cases": [
6+
{
7+
"name": "min sort with slice",
8+
"expression": "sort(@)[:3]",
9+
"result": [2, 3, 5]
10+
},
11+
{
12+
"name": "max sort with slice",
13+
"expression": "sort(@)[-3:]",
14+
"result": [972, 988, 989]
15+
}
16+
]
17+
}
18+
File renamed without changes.
File renamed without changes.

perf/perftest.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,20 @@
2323
from jmespath.lexer import Lexer
2424

2525

26-
DIRECTORY = os.path.join(os.path.dirname(os.path.abspath(__file__)))
27-
DEFAULT_NUM_LOOP = 1000
26+
DIRECTORY = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'cases')
27+
DEFAULT_NUM_LOOP = 100
2828

2929

3030
def run_tests(tests):
3131
times = []
3232
for test in tests:
3333
given = test['given']
3434
expression = test['expression']
35+
result = test['result']
3536
lex_time = _lex_time(expression)
3637
parse_time = _parse_time(expression)
3738
search_time = _search_time(expression, given)
38-
combined_time = _combined_time(expression, given)
39+
combined_time = _combined_time(expression, given, result)
3940
sys.stdout.write(
4041
"lex_time: %.5fms, parse_time: %.5fms, search_time: %.5fms "
4142
"combined_time: %.5fms " % (1000 * lex_time,
@@ -86,15 +87,18 @@ def _parse_time(expression, clock=_clock):
8687
return best
8788

8889

89-
def _combined_time(expression, given, clock=_clock):
90+
def _combined_time(expression, given, result, clock=_clock):
9091
best = float('inf')
9192
p = Parser()
9293
for i in range(DEFAULT_NUM_LOOP):
9394
p.purge()
9495
start = clock()
95-
p.parse(expression).search(given)
96+
r = p.parse(expression).search(given)
9697
end = clock()
9798
total = end - start
99+
if r != result:
100+
raise RuntimeError("Unexpected result, received: %s, "
101+
"expected: %s" % (r, result))
98102
if total < best:
99103
best = total
100104
return best

0 commit comments

Comments
 (0)