2626set_time_limit (0 );
2727@ini_set ('memory_limit ' , '256M ' );
2828
29- $ line = str_pad ("- " , 78 , "- " );
30- $ padHeader = 76 ;
29+ $ line = str_pad ("- " , 91 , "- " );
30+ $ padHeader = 89 ;
3131$ padInfo = 18 ;
3232$ padLabel = 31 ;
3333
4040$ arrayDimensionLimit = 300 ;
4141// That limit gives around 256Mb too
4242$ stringConcatLoopRepeat = 1 ;
43- $ stringConcatLoopLimit = 14000000 ;
43+ $ stringConcatLoopLimit = 7760000 ;
4444
4545function get_microtime ()
4646{
@@ -120,6 +120,10 @@ function getSystemMemInfo()
120120 $ data = explode ("\n" , file_get_contents ("/proc/meminfo " ));
121121 $ meminfo = array ();
122122 foreach ($ data as $ line ) {
123+ if (empty ($ line )) {
124+ continue ;
125+ }
126+ 123127 list ($ key , $ val ) = explode (": " , $ line );
124128 $ _val = explode ("" , strtolower (trim ($ val )));
125129 $ val = intval ($ _val [0 ]);
@@ -253,7 +257,7 @@ function getCpuInfo($fireUpCpu = false)
253257/**
254258 * @return array((int)seconds, (str)seconds, (str)operations/sec), (str)opterations/MHz)
255259 */
256- function format_result_test ($ diffSeconds , $ opCount )
260+ function format_result_test ($ diffSeconds , $ opCount, $ memory = 0 )
257261{
258262 global $ cpuInfo ;
259263 if ($ diffSeconds ) {
@@ -271,9 +275,10 @@ function format_result_test($diffSeconds, $opCount)
271275 return array ($ diffSeconds , number_format ($ diffSeconds , 3 , '. ' , '' ),
272276 number_format ($ ops_v , 2 , '. ' , '' ) . '' . $ ops_u ,
273277 number_format ($ opmhz_v , 2 , '. ' , '' ) . '' . $ opmhz_u ,
278+ convert ($ memory )
274279 );
275280 } else {
276- return array (0 , '0.000 ' , 'x.xx ' , 'x.xx ' );
281+ return array (0 , '0.000 ' , 'x.xx ' , 'x.xx ' , 0 );
277282 }
278283}
279284
@@ -291,7 +296,7 @@ function test_01_Math($count = 1400000)
291296 $ r = call_user_func_array ($ function , array ($ i ));
292297 }
293298 }
294- return format_result_test (get_microtime () - $ time_start , $ count );
299+ return format_result_test (get_microtime () - $ time_start , $ count, memory_get_usage ( true ) );
295300}
296301
297302function test_02_String_Concat ()
@@ -302,10 +307,10 @@ function test_02_String_Concat()
302307 for ($ r = 0 ; $ r < $ stringConcatLoopRepeat ; ++$ r ) {
303308 $ s = '' ;
304309 for ($ i = 0 ; $ i < $ stringConcatLoopLimit ; ++$ i ) {
305- $ s .= '- Valar moghulis ' . PHP_EOL ;
310+ $ s .= '- Valar dohaeris ' . PHP_EOL ;
306311 }
307312 }
308- return format_result_test (get_microtime () - $ time_start , $ stringConcatLoopLimit *$ stringConcatLoopRepeat );
313+ return format_result_test (get_microtime () - $ time_start , $ stringConcatLoopLimit *$ stringConcatLoopRepeat, memory_get_usage ( true ) );
309314}
310315
311316function test_03_String_Simple_Functions ($ count = 1300000 )
@@ -323,7 +328,7 @@ function test_03_String_Simple_Functions($count = 1300000)
323328 $ r = call_user_func_array ($ function , array ($ stringTest ));
324329 }
325330 }
326- return format_result_test (get_microtime () - $ time_start , $ count );
331+ return format_result_test (get_microtime () - $ time_start , $ count, memory_get_usage ( true ) );
327332}
328333
329334function test_04_String_Multibyte ($ count = 130000 )
@@ -346,7 +351,7 @@ function test_04_String_Multibyte($count = 130000)
346351 $ r = call_user_func_array ($ function , array ($ stringTest ));
347352 }
348353 }
349- return format_result_test (get_microtime () - $ time_start , $ count );
354+ return format_result_test (get_microtime () - $ time_start , $ count, memory_get_usage ( true ) );
350355}
351356
352357function test_05_String_Manipulation ($ count = 1300000 )
@@ -364,7 +369,7 @@ function test_05_String_Manipulation($count = 1300000)
364369 $ r = call_user_func_array ($ function , array ($ stringTest ));
365370 }
366371 }
367- return format_result_test (get_microtime () - $ time_start , $ count );
372+ return format_result_test (get_microtime () - $ time_start , $ count, memory_get_usage ( true ) );
368373}
369374
370375function test_06_Regex ($ count = 1300000 )
@@ -382,7 +387,7 @@ function test_06_Regex($count = 1300000)
382387 $ r = call_user_func_array ($ function , array ($ regexPattern , $ stringTest ));
383388 }
384389 }
385- return format_result_test (get_microtime () - $ time_start , $ count );
390+ return format_result_test (get_microtime () - $ time_start , $ count, memory_get_usage ( true ) );
386391}
387392
388393function test_07_1_Hashing ($ count = 1300000 )
@@ -400,7 +405,7 @@ function test_07_1_Hashing($count = 1300000)
400405 $ r = call_user_func_array ($ function , array ($ stringTest ));
401406 }
402407 }
403- return format_result_test (get_microtime () - $ time_start , $ count );
408+ return format_result_test (get_microtime () - $ time_start , $ count, memory_get_usage ( true ) );
404409}
405410
406411function test_07_2_Crypt ($ count = 10000 )
@@ -418,7 +423,7 @@ function test_07_2_Crypt($count = 10000)
418423 $ r = call_user_func_array ($ function , array ($ stringTest , '_J9..rasm ' ));
419424 }
420425 }
421- return format_result_test (get_microtime () - $ time_start , $ count );
426+ return format_result_test (get_microtime () - $ time_start , $ count, memory_get_usage ( true ) );
422427}
423428
424429function test_08_Json_Encode ($ count = 1300000 )
@@ -444,7 +449,7 @@ function test_08_Json_Encode($count = 1300000)
444449 $ r = json_encode ($ value );
445450 }
446451 }
447- return format_result_test (get_microtime () - $ time_start , $ count );
452+ return format_result_test (get_microtime () - $ time_start , $ count, memory_get_usage ( true ) );
448453}
449454
450455function test_09_Json_Decode ($ count = 1300000 )
@@ -473,7 +478,7 @@ function test_09_Json_Decode($count = 1300000)
473478 $ r = json_decode ($ value );
474479 }
475480 }
476- return format_result_test (get_microtime () - $ time_start , $ count );
481+ return format_result_test (get_microtime () - $ time_start , $ count, memory_get_usage ( true ) );
477482}
478483
479484function test_10_Serialize ($ count = 1300000 )
@@ -499,7 +504,7 @@ function test_10_Serialize($count = 1300000)
499504 $ r = serialize ($ value );
500505 }
501506 }
502- return format_result_test (get_microtime () - $ time_start , $ count );
507+ return format_result_test (get_microtime () - $ time_start , $ count, memory_get_usage ( true ) );
503508}
504509
505510function test_11_Unserialize ($ count = 1300000 )
@@ -528,7 +533,7 @@ function test_11_Unserialize($count = 1300000)
528533 $ r = unserialize ($ value );
529534 }
530535 }
531- return format_result_test (get_microtime () - $ time_start , $ count );
536+ return format_result_test (get_microtime () - $ time_start , $ count, memory_get_usage ( true ) );
532537}
533538
534539function test_12_Array_Fill ()
@@ -543,7 +548,7 @@ function test_12_Array_Fill()
543548 }
544549 }
545550 }
546- return format_result_test (get_microtime () - $ time_start , pow ($ arrayDimensionLimit , 2 )*$ arrayTestLoopLimit );
551+ return format_result_test (get_microtime () - $ time_start , pow ($ arrayDimensionLimit , 2 )*$ arrayTestLoopLimit, memory_get_usage ( true ) );
547552}
548553
549554function test_13_Array_Unset ()
@@ -564,7 +569,7 @@ function test_13_Array_Unset()
564569 unset($ X [$ i ]);
565570 }
566571 }
567- return format_result_test (get_microtime () - $ time_start , pow ($ arrayDimensionLimit , 2 )*$ arrayTestLoopLimit );
572+ return format_result_test (get_microtime () - $ time_start , pow ($ arrayDimensionLimit , 2 )*$ arrayTestLoopLimit, memory_get_usage ( true ) );
568573}
569574
570575function test_14_Loops ($ count = 190000000 )
@@ -573,7 +578,7 @@ function test_14_Loops($count = 190000000)
573578 for ($ i = 0 ; $ i < $ count ; ++$ i ) ;
574579 $ i = 0 ;
575580 while ($ i ++ < $ count ) ;
576- return format_result_test (get_microtime () - $ time_start , $ count * 2 );
581+ return format_result_test (get_microtime () - $ time_start , $ count * 2 , memory_get_usage ( true ) );
577582}
578583
579584function test_15_Loop_IfElse ($ count = 90000000 )
@@ -586,7 +591,7 @@ function test_15_Loop_IfElse($count = 90000000)
586591 } else {
587592 }
588593 }
589- return format_result_test (get_microtime () - $ time_start , $ count );
594+ return format_result_test (get_microtime () - $ time_start , $ count, memory_get_usage ( true ) );
590595}
591596
592597function test_16_Loop_Ternary ($ count = 90000000 )
@@ -601,7 +606,7 @@ function test_16_Loop_Ternary($count = 90000000)
601606 : 1 )
602607 : 0 ;
603608 }
604- return format_result_test (get_microtime () - $ time_start , $ count );
609+ return format_result_test (get_microtime () - $ time_start , $ count, memory_get_usage ( true ) );
605610}
606611
607612function test_17_1_Loop_Defined_Access ($ count = 20000000 )
@@ -612,7 +617,7 @@ function test_17_1_Loop_Defined_Access($count = 20000000)
612617 for ($ i = 0 ; $ i < $ count ; $ i ++) {
613618 $ r += $ a [$ i % 2 ];
614619 }
615- return format_result_test (get_microtime () - $ time_start , $ count );
620+ return format_result_test (get_microtime () - $ time_start , $ count, memory_get_usage ( true ) );
616621}
617622
618623function test_17_2_Loop_Undefined_Access ($ count = 20000000 )
@@ -623,7 +628,7 @@ function test_17_2_Loop_Undefined_Access($count = 20000000)
623628 for ($ i = 0 ; $ i < $ count ; $ i ++) {
624629 $ r += @$ a [$ i % 2 ] ? 0 : 1 ;
625630 }
626- return format_result_test (get_microtime () - $ time_start , $ count );
631+ return format_result_test (get_microtime () - $ time_start , $ count, memory_get_usage ( true ) );
627632}
628633
629634$ version = explode ('. ' , PHP_VERSION );
@@ -650,16 +655,16 @@ function test_17_2_Loop_Undefined_Access($count = 20000000)
650655 . str_pad ("Platform: " , $ padInfo ) . " : " . PHP_OS . "\n"
651656 . "$ line \n"
652657 . str_pad ('TEST NAME ' , $ padLabel ) . " : "
653- . str_pad ('SECONDS ' , 8 + 4 , '' , STR_PAD_LEFT ) . " | " . str_pad ('OP/SEC ' , 9 + 4 , '' , STR_PAD_LEFT ) . " | " . str_pad ('OP/SEC/MHz ' , 9 + 7 , '' , STR_PAD_LEFT ) . "\n"
658+ . str_pad ('SECONDS ' , 8 + 4 , '' , STR_PAD_LEFT ) . " | " . str_pad ('OP/SEC ' , 9 + 4 , '' , STR_PAD_LEFT ) . " | " . str_pad ('OP/SEC/MHz ' , 9 + 7 , '' , STR_PAD_LEFT ) . " | " . str_pad ( ' MEMORY ' , 10 , ' ' , STR_PAD_LEFT ) . " \n"
654659 . "$ line \n" ;
655660
656661foreach ($ functions ['user ' ] as $ user ) {
657662 if (preg_match ('/^test_/ ' , $ user )) {
658663 $ testName = str_replace ('test_ ' , '' , $ user );
659664 echo str_pad ($ testName , $ padLabel ) . " : " ;
660- list ($ resultSec , $ resultSecFmt , $ resultOps , $ resultOpMhz ) = $ user ();
665+ list ($ resultSec , $ resultSecFmt , $ resultOps , $ resultOpMhz, $ memory ) = $ user ();
661666 $ total += $ resultSec ;
662- echo str_pad ($ resultSecFmt , 8 , '' , STR_PAD_LEFT ) . " sec | " . str_pad ($ resultOps , 9 , '' , STR_PAD_LEFT ) . "Op/s | " . str_pad ($ resultOpMhz , 9 , '' , STR_PAD_LEFT ) . "Ops/MHz " . "\n" ;
667+ echo str_pad ($ resultSecFmt , 8 , '' , STR_PAD_LEFT ) . " sec | " . str_pad ($ resultOps , 9 , '' , STR_PAD_LEFT ) . "Op/s | " . str_pad ($ resultOpMhz , 9 , '' , STR_PAD_LEFT ) . "Ops/MHz | " . str_pad ( $ memory , 10 , ' ' , STR_PAD_LEFT ) . "\n" ;
663668 }
664669}
665670
0 commit comments