1313define ('MIN_TOTAL_DURATION ' , 5 );
1414$ start = microtime (true );
1515
16- if ($ _SERVER ['argc ' ] == 1 ) {
16+ if ($ _SERVER ['argc ' ] === 1 ) {
1717 $ files = glob (__DIR__ . '/**/*.php ' );
1818} else {
19- // Force absolute path
20- $ files = array_map (function ($ file ) {
21- return $ file [0 ] == DIRECTORY_SEPARATOR ? $ file : $ _SERVER ['PWD ' ] . DIRECTORY_SEPARATOR . $ file ;
22- }, array_slice ($ _SERVER ['argv ' ], 1 ));
19+ $ files = [];
20+ foreach (array_slice ($ _SERVER ['argv ' ], 1 ) as $ fileOrDir ) {
21+ if (is_dir ($ fileOrDir )) {
22+ $ files = array_merge ($ files , glob ($ fileOrDir . '/*.php ' ));
23+ } else {
24+ // Force absolute path
25+ $ files [] = $ file [0 ] === DIRECTORY_SEPARATOR ? $ file : $ _SERVER ['PWD ' ] . DIRECTORY_SEPARATOR . $ file ;
26+ }
27+ }
2328}
2429
2530
2631Observable::just ($ files )
2732 ->doOnNext (function (array $ files ) {
2833 printf ("Benchmarking %d file/s (min %ds each) \n" , count ($ files ), MIN_TOTAL_DURATION );
29- printf ("script_name - total_runs (single_run_mean ±standard_variant ) \n" );
30- printf ("============================================================ \n" );
34+ printf ("script_name - total_runs (single_run_mean ±standard_deviation ) \n" );
35+ printf ("============================================================== \n" );
3136 })
3237 ->concatMap (function ($ files ) { // Flatten the array
3338 return Observable::fromArray ($ files );
@@ -73,7 +78,7 @@ function () { }
7378 ->doOnNext (function (array $ result ) { // Print the number of successful runs
7479 printf (' - %d ' , count ($ result ['durations ' ]));
7580 })
76- ->map (function (array $ result ) { // Calculate the standard deviance
81+ ->map (function (array $ result ) { // Calculate the standard deviation
7782 $ count = count ($ result ['durations ' ]);
7883 $ mean = array_sum ($ result ['durations ' ]) / $ count ;
7984
@@ -84,12 +89,12 @@ function () { }
8489 return [
8590 'file ' => $ result ['file ' ],
8691 'mean ' => $ mean ,
87- 'standard_variance ' => pow ($ variance / $ count , 0.5 ),
92+ 'standard_deviation ' => pow ($ variance / $ count , 0.5 ),
8893 ];
8994 })
9095 ->subscribe (new CallbackObserver (
9196 function (array $ result ) {
92- printf (" (%.2fms ±%.2fms) \n" , $ result ['mean ' ], $ result ['standard_variance ' ]);
97+ printf (" (%.2fms ±%.2fms) \n" , $ result ['mean ' ], $ result ['standard_deviation ' ]);
9398 },
9499 function (\Exception $ error ) {
95100 printf ("\nError: %s \n" , $ error ->getMessage ());
0 commit comments