Skip to content

Commit 37585f6

Browse files
committed
Fixing perf test and TreeCompiler
1 parent 0b7ce31 commit 37585f6

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

bin/perf.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,29 @@
55
$dir = isset($argv[1]) ? $argv[1] : __DIR__ . '/../tests/compliance/perf';
66
is_dir($dir) or die('Dir not found: ' . $dir);
77
// Warm up the runner
8-
\JmesPath\Env::createRuntime()->search('foo', []);
9-
// Run the test suites.
10-
array_map('runSuite', glob($dir . '/*.json'));
8+
\JmesPath\Env::search('foo', []);
9+
10+
$total = 0;
11+
foreach (glob($dir . '/*.json') as $file) {
12+
$total += runSuite($file);
13+
}
14+
echo "\nTotal time: {$total}\n";
1115

1216
function runSuite($file)
1317
{
1418
$contents = file_get_contents($file);
1519
$json = json_decode($contents, true);
20+
$total = 0;
1621
foreach ($json as $suite) {
1722
foreach ($suite['cases'] as $case) {
18-
runCase(
23+
$total += runCase(
1924
str_replace(getcwd(), '.', $file),
2025
$suite['given'],
2126
$case['expression']
2227
);
2328
}
2429
}
30+
return $total;
2531
}
2632

2733
function runCase($file, $given, $expression)
@@ -31,7 +37,7 @@ function runCase($file, $given, $expression)
3137

3238
for ($i = 0; $i < 1000; $i++) {
3339
$t = microtime(true);
34-
$runtime->search($expression, $given);
40+
$runtime($expression, $given);
3541
$tryTime = (microtime(true) - $t) * 1000;
3642
if ($tryTime < $best) {
3743
$best = $tryTime;
@@ -48,4 +54,6 @@ function runCase($file, $given, $expression)
4854
$template = "time: %fms, %s: %s\n";
4955
$expression = str_replace("\n", '\n', $expression);
5056
printf($template, $best, basename($file), substr($expression, 0, 50));
57+
58+
return $best;
5159
}

src/TreeCompiler.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ public function visit(array $ast, $fnName, $expr)
3333
->outdent()
3434
->write('}');
3535

36-
echo $this->source;
37-
3836
return $this->source;
3937
}
4038

src/TreeInterpreter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ private function dispatch(array $node, $value)
255255
case 'expression':
256256
$apply = $node['children'][0];
257257
return function ($value) use ($apply) {
258-
$this->visit($apply, $value);
258+
return $this->visit($apply, $value);
259259
};
260260

261261
default:

0 commit comments

Comments
 (0)