10
10
# Author : Sergey Dryabzhinsky #
11
11
# Company : Rusoft Ltd, Russia #
12
12
# Date : May 15, 2017 #
13
- # version : 1.0.14 #
13
+ # version : 1.0.15 #
14
14
# License : Creative Commons CC-BY license #
15
15
# Website : https://github.com/rusoft/php-simple-benchmark-script #
16
16
# Website : https://git.rusoft.ru/open-source/php-simple-benchmark-script #
17
17
# #
18
18
################################################################################
19
19
*/
20
20
21
- $ scriptVersion = '1.0.14 ' ;
21
+ $ scriptVersion = '1.0.15 ' ;
22
+
23
+ // Used in hacks/fixes checks
24
+ $ phpversion = explode ('. ' , PHP_VERSION );
22
25
23
26
$ stringTest = " the quick <b>brown</b> fox jumps <i>over</i> the lazy dog and eat <span>lorem ipsum</span><br/> Valar morghulis <br/> \n\rабыр \nвалар дохаэрис " ;
24
27
$ regexPattern = '/[\s,]+/ ' ;
25
28
26
- set_time_limit (0 );
29
+ set_time_limit (600 );
27
30
@ini_set ('memory_limit ' , '256M ' );
28
31
29
32
$ line = str_pad ("- " , 91 , "- " );
30
33
$ padHeader = 89 ;
31
34
$ padInfo = 18 ;
32
35
$ padLabel = 31 ;
33
36
34
- $ emptyResult = array (0 , '-.--- ' , '-.-- ' , '-.-- ' );
37
+ $ emptyResult = array (0 , '-.--- ' , '-.-- ' , '-.-- ' , 0 );
35
38
36
39
// That gives around 256Mb memory use and reasonable test time
40
+ $ testMemoryFull = 256 *1024 *1024 ;
37
41
// Arrays are matrix [$dimention] x [$dimention]
38
- $ arrayTestMemoryMinimum = 256 *1024 *1024 ;
39
42
$ arrayTestLoopLimit = 300 ;
40
43
$ arrayDimensionLimit = 300 ;
41
44
// That limit gives around 256Mb too
42
45
$ stringConcatLoopRepeat = 1 ;
43
- $ stringConcatLoopLimit = 7760000 ;
46
+ // Nice dice roll
47
+ $ stringConcatLoopLimit = 7700000 ;
44
48
45
49
function get_microtime ()
46
50
{
@@ -233,22 +237,28 @@ function getCpuInfo($fireUpCpu = false)
233
237
}
234
238
235
239
$ memoryLimit = min (getPhpMemoryLimitBytes (), getSystemMemoryFreeLimitBytes ());
236
- $ memoryLimitMb = number_format ($ memoryLimit/ 1024.0 / 1024.0 , 1 , ' . ' , '' );
240
+ $ memoryLimitMb = convert ($ memoryLimit );
237
241
238
242
// Adjust array tests limits
239
- if ($ memoryLimit < $ arrayTestMemoryMinimum ) {
243
+ if ($ memoryLimit < $ testMemoryFull ) {
240
244
241
245
print ("<pre> \n<<< WARNING >>> \nAvailable memory for tests: " .$ memoryLimitMb
242
- ." MB is less than minimum required: " .number_format ( $ arrayTestMemoryMinimum / 1024.0 / 1024.0 , 1 , ' . ' , '' )
243
- ." MB . \n Recalculate tests parameters to fit in memory limits. "
246
+ ." is less than minimum required: " .convert ( $ testMemoryFull )
247
+ .". \n Recalculate tests parameters to fit in memory limits. "
244
248
."\n</pre> " . PHP_EOL );
245
249
246
- $ factor = 1.0 * ($ arrayTestMemoryMinimum - $ memoryLimit ) / $ arrayTestMemoryMinimum ;
250
+ $ factor = 1.0 * ($ testMemoryFull - $ memoryLimit ) / $ testMemoryFull ;
247
251
$ diff = (int )($ factor * $ arrayDimensionLimit );
248
252
$ arrayTestLoopLimit += (int )(1.0 * pow ($ arrayDimensionLimit , 2 ) * $ arrayTestLoopLimit / pow ($ arrayDimensionLimit - $ diff , 2 ));
249
253
$ arrayDimensionLimit -= $ diff ;
250
254
251
255
$ diff = (int )($ factor * $ stringConcatLoopLimit );
256
+
257
+ // Special hack for php-7.x
258
+ // New string classes, new memory allocator
259
+ // Consumes more, allocate huge blocks
260
+ if ((int )$ phpversion [0 ] >= 7 ) $ diff = (int )($ diff * 1.1 );
261
+
252
262
$ stringConcatLoopRepeat = (int )(1.0 * ($ stringConcatLoopLimit * $ stringConcatLoopRepeat ) / ($ stringConcatLoopLimit - $ diff ));
253
263
$ stringConcatLoopLimit -= $ diff ;
254
264
}
@@ -631,8 +641,7 @@ function test_17_2_Loop_Undefined_Access($count = 20000000)
631
641
return format_result_test (get_microtime () - $ time_start , $ count , memory_get_usage (true ));
632
642
}
633
643
634
- $ version = explode ('. ' , PHP_VERSION );
635
- if ((int )$ version [0 ] >= 5 ) {
644
+ if ((int )$ phpversion [0 ] >= 5 ) {
636
645
include_once 'php5.inc ' ;
637
646
}
638
647
@@ -649,7 +658,7 @@ function test_17_2_Loop_Undefined_Access($count = 20000000)
649
658
. str_pad ("model " , $ padInfo , ' ' , STR_PAD_LEFT ) . " : " . $ cpuInfo ['model ' ] . "\n"
650
659
. str_pad ("cores " , $ padInfo , ' ' , STR_PAD_LEFT ) . " : " . $ cpuInfo ['cores ' ] . "\n"
651
660
. str_pad ("MHz " , $ padInfo , ' ' , STR_PAD_LEFT ) . " : " . $ cpuInfo ['mhz ' ] . 'MHz ' . "\n"
652
- . str_pad ("Memory " , $ padInfo ) . " : " . $ memoryLimitMb . 'MB available ' . "\n"
661
+ . str_pad ("Memory " , $ padInfo ) . " : " . $ memoryLimitMb . ' available ' . "\n"
653
662
. str_pad ("PHP version: " , $ padInfo ) . " : " . PHP_VERSION . "\n"
654
663
. str_pad ("Benchmark version: " , $ padInfo ) . " : " . $ scriptVersion . "\n"
655
664
. str_pad ("Platform: " , $ padInfo ) . " : " . PHP_OS . "\n"
0 commit comments