55$ dir = isset ($ argv [1 ]) ? $ argv [1 ] : __DIR__ . '/../tests/compliance/perf ' ;
66is_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
1216function 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
2733function 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}
0 commit comments