28
28
$ files = array_merge ($ files , glob ($ fileOrDir . '/*.php ' ));
29
29
} else {
30
30
// Force absolute path
31
- $ files [] = $ file [0 ] === DIRECTORY_SEPARATOR ? $ file : $ _SERVER ['PWD ' ] . DIRECTORY_SEPARATOR . $ file ;
31
+ $ files [] = $ fileOrDir [0 ] === DIRECTORY_SEPARATOR ? $ fileOrDir : $ _SERVER ['PWD ' ] . DIRECTORY_SEPARATOR . $ fileOrDir ;
32
32
}
33
33
}
34
34
}
37
37
Observable::just ($ files )
38
38
->doOnNext (function (array $ files ) {
39
39
printf ("Benchmarking %d file/s (min %ds each) \n" , count ($ files ), MIN_TOTAL_DURATION );
40
- printf ("script_name - total_runs (single_run_mean ±standard_deviation) \n" );
40
+ printf ("script_name - total_runs (single_run_mean ±standard_deviation) - mem_start [mem_100_iter] mem_end \n" );
41
41
printf ("============================================================== \n" );
42
42
})
43
43
->concatMap (function ($ files ) { // Flatten the array
@@ -63,6 +63,8 @@ function () { }
63
63
throw new Exception ("Unable to load file \"$ file \"" );
64
64
}
65
65
66
+ $ memoryUsage = [memory_get_usage ()];
67
+
66
68
while ($ totalDuration < MIN_TOTAL_DURATION ) {
67
69
$ start = microtime (true );
68
70
@@ -72,13 +74,20 @@ function () { }
72
74
73
75
$ durations [] = $ duration * 1000 ;
74
76
$ totalDuration += $ duration ;
77
+
78
+ if (count ($ durations ) === 100 ) {
79
+ $ memoryUsage [] = memory_get_usage ();
80
+ }
75
81
}
76
82
83
+ $ memoryUsage [] = memory_get_usage ();
84
+
77
85
ob_end_clean ();
78
86
79
87
return [
80
88
'file ' => $ file ,
81
89
'durations ' => $ durations ,
90
+ 'memory_usage ' => $ memoryUsage ,
82
91
];
83
92
})
84
93
->doOnNext (function (array $ result ) { // Print the number of successful runs
@@ -94,13 +103,18 @@ function () { }
94
103
95
104
return [
96
105
'file ' => $ result ['file ' ],
106
+ 'memory_usage ' => $ result ['memory_usage ' ],
97
107
'mean ' => $ mean ,
98
108
'standard_deviation ' => pow ($ variance / $ count , 0.5 ),
99
109
];
100
110
})
101
111
->subscribe (new CallbackObserver (
102
112
function (array $ result ) {
103
- printf (" (%.2fms ±%.2fms) \n" , $ result ['mean ' ], $ result ['standard_deviation ' ]);
113
+ printf (" (%.2fms ±%.2fms) - " , $ result ['mean ' ], $ result ['standard_deviation ' ]);
114
+ foreach ($ result ['memory_usage ' ] as $ memory ) {
115
+ printf ("%.2fMB " , $ memory / pow (10 , 6 ));
116
+ }
117
+ printf ("\n" );
104
118
},
105
119
function (\Exception $ error ) {
106
120
printf ("\nError: %s \n" , $ error ->getMessage ());
0 commit comments