31
31
$ dropDead = true ;
32
32
}
33
33
if ($ dropDead ) {
34
- print ('<pre><<< ERROR >>> Need PHP 4.3+! Current version is ' . PHP_VERSION . '</pre> ' );
34
+ print ('<pre><<< ERROR >>> Need PHP 4.3+! Current version is ' . PHP_VERSION . '</pre> ' );
35
35
exit (1 );
36
36
}
37
37
61
61
}
62
62
63
63
// http://php.net/manual/ru/function.getopt.php example #2
64
- $ shortopts = "h " ;
65
- $ shortopts .= "m: " ;// Обязательное значение
66
- $ shortopts .= "t: " ;// Обязательное значение
64
+ $ shortopts = "h " ;
65
+ $ shortopts .= "m: " ;// Обязательное значение
66
+ $ shortopts .= "t: " ;// Обязательное значение
67
67
68
- $ longopts = array (
68
+ $ longopts = array (
69
69
"help " ,
70
- "memory-limit: " ,// Обязательное значение
71
- "time-limit: " ,// Обязательное значение
70
+ "memory-limit: " ,// Обязательное значение
71
+ "time-limit: " ,// Обязательное значение
72
72
);
73
73
74
74
$ hasLongOpts = true ;
91
91
case 'help ' :
92
92
if ($ hasLongOpts ) {
93
93
print (
94
- '<pre> ' . PHP_EOL
95
- . 'PHP Benchmark Performance Script, version ' . $ scriptVersion . PHP_EOL
96
- . PHP_EOL
97
- . 'Usage: ' . basename (__FILE__ ). ' [-h|--help] [-m|--memory-limit=256] [-t|--time-limit=600] ' . PHP_EOL
98
- . PHP_EOL
99
- . ' -h|--help - print this help and exit ' . PHP_EOL
100
- . ' -m|--memory-limit <Mb> - set memory_limit value in Mb, defaults to 256 (Mb) ' . PHP_EOL
101
- . ' -t|--time-limit <sec> - set max_execution_time value in seconds, defaults to 600 (sec) ' . PHP_EOL
102
- . PHP_EOL
103
- . 'Example: php ' . basename (__FILE__ ). ' -m=64 -t=30 ' . PHP_EOL
104
- . '</pre> ' . PHP_EOL
94
+ '<pre> ' . PHP_EOL
95
+ . 'PHP Benchmark Performance Script, version ' . $ scriptVersion . PHP_EOL
96
+ . PHP_EOL
97
+ . 'Usage: ' . basename (__FILE__ ) . ' [-h|--help] [-m|--memory-limit=256] [-t|--time-limit=600] ' . PHP_EOL
98
+ . PHP_EOL
99
+ . ' -h|--help - print this help and exit ' . PHP_EOL
100
+ . ' -m|--memory-limit <Mb> - set memory_limit value in Mb, defaults to 256 (Mb) ' . PHP_EOL
101
+ . ' -t|--time-limit <sec> - set max_execution_time value in seconds, defaults to 600 (sec) ' . PHP_EOL
102
+ . PHP_EOL
103
+ . 'Example: php ' . basename (__FILE__ ) . ' -m=64 -t=30 ' . PHP_EOL
104
+ . '</pre> ' . PHP_EOL
105
105
);
106
106
} else {
107
107
print (
108
- '<pre> ' . PHP_EOL
109
- . 'PHP Benchmark Performance Script, version ' . $ scriptVersion . PHP_EOL
110
- . PHP_EOL
111
- . 'Usage: ' . basename (__FILE__ ). ' [-h] [-m 256] [-t 600] ' . PHP_EOL
112
- . PHP_EOL
113
- . ' -h - print this help and exit ' . PHP_EOL
114
- . ' -m <Mb> - set memory_limit value in Mb, defaults to 256 (Mb) ' . PHP_EOL
115
- . ' -t <sec> - set max_execution_time value in seconds, defaults to 600 (sec) ' . PHP_EOL
116
- . PHP_EOL
117
- . 'Example: php ' . basename (__FILE__ ). ' -m 64 -t 30 ' . PHP_EOL
118
- . '</pre> ' . PHP_EOL
108
+ '<pre> ' . PHP_EOL
109
+ . 'PHP Benchmark Performance Script, version ' . $ scriptVersion . PHP_EOL
110
+ . PHP_EOL
111
+ . 'Usage: ' . basename (__FILE__ ) . ' [-h] [-m 256] [-t 600] ' . PHP_EOL
112
+ . PHP_EOL
113
+ . ' -h - print this help and exit ' . PHP_EOL
114
+ . ' -m <Mb> - set memory_limit value in Mb, defaults to 256 (Mb) ' . PHP_EOL
115
+ . ' -t <sec> - set max_execution_time value in seconds, defaults to 600 (sec) ' . PHP_EOL
116
+ . PHP_EOL
117
+ . 'Example: php ' . basename (__FILE__ ) . ' -m 64 -t 30 ' . PHP_EOL
118
+ . '</pre> ' . PHP_EOL
119
119
);
120
120
}
121
121
exit (0 );
126
126
if ((int )$ oval ) {
127
127
$ defaultMemoryLimit = (int )$ oval ;
128
128
} else {
129
- print ("<pre><<< WARNING >>> Option ' $ okey' has not numeric value ' $ oval'! Skip.</pre> " . PHP_EOL );
129
+ print ("<pre><<< WARNING >>> Option ' $ okey' has not numeric value ' $ oval'! Skip.</pre> " . PHP_EOL );
130
130
}
131
131
break ;
132
132
135
135
if ((int )$ oval ) {
136
136
$ defaultTimeLimit = (int )$ oval ;
137
137
} else {
138
- print ("<pre><<< WARNING >>> Option ' $ okey' has not numeric value ' $ oval'! Skip.</pre> " . PHP_EOL );
138
+ print ("<pre><<< WARNING >>> Option ' $ okey' has not numeric value ' $ oval'! Skip.</pre> " . PHP_EOL );
139
139
}
140
140
break ;
141
141
142
142
default :
143
- print ("<pre><<< WARNING >>> Unknown option ' $ okey'!</pre> " . PHP_EOL );
143
+ print ("<pre><<< WARNING >>> Unknown option ' $ okey'!</pre> " . PHP_EOL );
144
144
}
145
145
146
146
}
171
171
$ cryptAlgoName = 'default ' ;
172
172
173
173
// That gives around 256Mb memory use and reasonable test time
174
- $ testMemoryFull = 256 * 1024 * 1024 ;
174
+ $ testMemoryFull = 256 * 1024 * 1024 ;
175
175
// Arrays are matrix [$dimention] x [$dimention]
176
176
$ arrayDimensionLimit = 400 ;
177
177
@@ -436,7 +436,6 @@ function dumb_test_Functions()
436
436
}
437
437
438
438
439
-
440
439
/** ---------------------------------- Code for common variables, tune values -------------------------------------------- */
441
440
442
441
// Search most common available algo for SALT
@@ -494,10 +493,10 @@ function dumb_test_Functions()
494
493
// Adjust array tests limits
495
494
if ($ memoryLimit < $ testMemoryFull ) {
496
495
497
- print ("<pre> \n<<< WARNING >>> \nAvailable memory for tests: " . $ memoryLimitMb
498
- ." is less than minimum required: " . convert ($ testMemoryFull )
499
- .". \n Recalculate tests parameters to fit in memory limits. "
500
- ."\n</pre> " . PHP_EOL );
496
+ print ("<pre> \n<<< WARNING >>> \nAvailable memory for tests: " . $ memoryLimitMb
497
+ ." is less than minimum required: " . convert ($ testMemoryFull )
498
+ .". \n Recalculate tests parameters to fit in memory limits. "
499
+ ."\n</pre> " . PHP_EOL );
501
500
502
501
$ factor = 1.0 * ($ testMemoryFull - $ memoryLimit ) / $ testMemoryFull ;
503
502
@@ -537,7 +536,7 @@ function dumb_test_Functions()
537
536
// Don't bother if time is unlimited
538
537
if ($ maxTime ) {
539
538
if ($ needTime > ($ maxTime - 1 )) {
540
- $ factor = 1.0 * ($ maxTime- 1 ) / $ needTime ;
539
+ $ factor = 1.0 * ($ maxTime - 1 ) / $ needTime ;
541
540
}
542
541
}
543
542
if ($ factor < 1.0 ) {
@@ -556,7 +555,7 @@ function dumb_test_Functions()
556
555
557
556
print ("<pre> \n<<< WARNING >>> \nMax execution time is less than needed for tests! \n Will try to reduce tests time as much as possible. \n</pre> " . PHP_EOL );
558
557
foreach ($ testsLoopLimits as $ tst => $ loops ) {
559
- $ testsLoopLimits [$ tst ] = (int )($ loops * $ factor );
558
+ $ testsLoopLimits [$ tst ] = (int )($ loops * $ factor );
560
559
}
561
560
}
562
561
@@ -625,9 +624,8 @@ function test_02_String_Concat()
625
624
for ($ i = 0 ; $ i < $ count ; ++$ i ) {
626
625
$ s .= '- Valar dohaeris ' . PHP_EOL ;
627
626
}
628
- $ s = '' ;
629
627
}
630
- return format_result_test (get_microtime () - $ time_start , $ count* $ stringConcatLoopRepeat , memory_get_usage (true ));
628
+ return format_result_test (get_microtime () - $ time_start , $ count * $ stringConcatLoopRepeat , memory_get_usage (true ));
631
629
}
632
630
633
631
function test_03_1_String_Number_Concat ()
@@ -638,7 +636,7 @@ function test_03_1_String_Number_Concat()
638
636
$ time_start = get_microtime ();
639
637
for ($ i = 0 ; $ i < $ count ; ++$ i ) {
640
638
$ f = $ i * 1.0 ;
641
- $ s = 'This is number ' . $ i . ' string concat. Число: ' . $ f . PHP_EOL ;
639
+ $ s = 'This is number ' . $ i . ' string concat. Число: ' . $ f . PHP_EOL ;
642
640
}
643
641
return format_result_test (get_microtime () - $ time_start , $ count , memory_get_usage (true ));
644
642
}
@@ -903,32 +901,45 @@ function test_13_Array_Fill()
903
901
$ X [$ i ][$ j ] = $ i * $ j ;
904
902
}
905
903
}
906
- unset($ X );
907
904
}
908
- return format_result_test (get_microtime () - $ time_start , pow ($ arrayDimensionLimit , 2 )* $ arrayTestLoopLimit , memory_get_usage (true ));
905
+ return format_result_test (get_microtime () - $ time_start , pow ($ arrayDimensionLimit , 2 ) * $ arrayTestLoopLimit , memory_get_usage (true ));
909
906
}
910
907
911
- function test_14_Array_Unset ()
908
+ function test_14_Array_Range ()
912
909
{
913
910
global $ testsLoopLimits , $ arrayDimensionLimit ;
914
911
915
912
$ arrayTestLoopLimit = $ testsLoopLimits ['14_array_loop ' ];
916
913
$ time_start = get_microtime ();
917
914
for ($ n = 0 ; $ n < $ arrayTestLoopLimit ; ++$ n ) {
915
+ $ x = range (0 , $ arrayDimensionLimit );
916
+ for ($ i = 0 ; $ i < $ arrayDimensionLimit ; $ i ++) {
917
+ $ x [$ i ] = range (0 , $ arrayDimensionLimit );
918
+ }
919
+ }
920
+ return format_result_test (get_microtime () - $ time_start , $ arrayDimensionLimit * $ arrayTestLoopLimit , memory_get_usage (true ));
921
+ }
918
922
919
- $ X = range (0 , $ arrayDimensionLimit );
920
- for ($ i = 0 ; $ i < $ arrayDimensionLimit ; ++$ i ) {
921
- $ X [$ i ] = range (0 , $ arrayDimensionLimit );
923
+ function test_14_Array_Unset ()
924
+ {
925
+ global $ testsLoopLimits , $ arrayDimensionLimit ;
926
+
927
+ $ arrayTestLoopLimit = $ testsLoopLimits ['14_array_loop ' ];
928
+ $ time_start = get_microtime ();
929
+ for ($ n = 0 ; $ n < $ arrayTestLoopLimit ; ++$ n ) {
930
+ $ x = range (0 , $ arrayDimensionLimit );
931
+ for ($ i = 0 ; $ i < $ arrayDimensionLimit ; $ i ++) {
932
+ $ x [$ i ] = range (0 , $ arrayDimensionLimit );
922
933
}
923
- for ($ i = $ arrayDimensionLimit - 1 ; $ i >= 0 ; $ i --) {
924
- for ($ j = 0 ; $ j < $ arrayDimensionLimit ; ++ $ j ) {
925
- unset($ X [$ i ][$ j ]);
934
+ for ($ i = $ arrayDimensionLimit ; $ i >= 0 ; $ i --) {
935
+ for ($ j = 0 ; $ j <= $ arrayDimensionLimit ; $ j ++ ) {
936
+ unset($ x [$ i ][$ j ]);
926
937
}
927
- unset($ X [$ i ]);
938
+ unset($ x [$ i ]);
928
939
}
929
- unset($ X );
940
+ unset($ x );
930
941
}
931
- return format_result_test (get_microtime () - $ time_start , pow ($ arrayDimensionLimit , 2 )* $ arrayTestLoopLimit , memory_get_usage (true ));
942
+ return format_result_test (get_microtime () - $ time_start , pow ($ arrayDimensionLimit , 2 ) * $ arrayTestLoopLimit , memory_get_usage (true ));
932
943
}
933
944
934
945
function test_15_Loops ()
@@ -1044,7 +1055,6 @@ function test_20_Type_Conversion()
1044
1055
}
1045
1056
1046
1057
1047
-
1048
1058
if ((int )$ phpversion [0 ] >= 5 ) {
1049
1059
if (is_file ('php5.inc ' )) {
1050
1060
include_once 'php5.inc ' ;
0 commit comments