Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 97471ee

Browse files
author
Sergey Dryabzhinsky
authored
Merge pull request #10 from ryr/master
переменная нужна для memory_get_usage, чистится после выполнения функции
2 parents a36b15c + 9cd2b16 commit 97471ee

File tree

1 file changed

+66
-56
lines changed

1 file changed

+66
-56
lines changed

‎bench.php‎

Lines changed: 66 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
$dropDead = true;
3232
}
3333
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>');
3535
exit(1);
3636
}
3737

@@ -61,14 +61,14 @@
6161
}
6262

6363
// 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:";// Обязательное значение
6767

68-
$longopts = array(
68+
$longopts = array(
6969
"help",
70-
"memory-limit:",// Обязательное значение
71-
"time-limit:",// Обязательное значение
70+
"memory-limit:",// Обязательное значение
71+
"time-limit:",// Обязательное значение
7272
);
7373

7474
$hasLongOpts = true;
@@ -91,31 +91,31 @@
9191
case 'help':
9292
if ($hasLongOpts) {
9393
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
105105
);
106106
} else {
107107
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
119119
);
120120
}
121121
exit(0);
@@ -126,7 +126,7 @@
126126
if ((int)$oval) {
127127
$defaultMemoryLimit = (int)$oval;
128128
} 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);
130130
}
131131
break;
132132

@@ -135,12 +135,12 @@
135135
if ((int)$oval) {
136136
$defaultTimeLimit = (int)$oval;
137137
} 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);
139139
}
140140
break;
141141

142142
default:
143-
print("<pre><<< WARNING >>> Unknown option '$okey'!</pre>".PHP_EOL);
143+
print("<pre><<< WARNING >>> Unknown option '$okey'!</pre>" . PHP_EOL);
144144
}
145145

146146
}
@@ -171,7 +171,7 @@
171171
$cryptAlgoName = 'default';
172172

173173
// That gives around 256Mb memory use and reasonable test time
174-
$testMemoryFull = 256*1024*1024;
174+
$testMemoryFull = 256 * 1024 * 1024;
175175
// Arrays are matrix [$dimention] x [$dimention]
176176
$arrayDimensionLimit = 400;
177177

@@ -436,7 +436,6 @@ function dumb_test_Functions()
436436
}
437437

438438

439-
440439
/** ---------------------------------- Code for common variables, tune values -------------------------------------------- */
441440

442441
// Search most common available algo for SALT
@@ -494,10 +493,10 @@ function dumb_test_Functions()
494493
// Adjust array tests limits
495494
if ($memoryLimit < $testMemoryFull) {
496495

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);
501500

502501
$factor = 1.0 * ($testMemoryFull - $memoryLimit) / $testMemoryFull;
503502

@@ -537,7 +536,7 @@ function dumb_test_Functions()
537536
// Don't bother if time is unlimited
538537
if ($maxTime) {
539538
if ($needTime > ($maxTime - 1)) {
540-
$factor = 1.0 * ($maxTime-1) / $needTime;
539+
$factor = 1.0 * ($maxTime - 1) / $needTime;
541540
}
542541
}
543542
if ($factor < 1.0) {
@@ -556,7 +555,7 @@ function dumb_test_Functions()
556555

557556
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);
558557
foreach ($testsLoopLimits as $tst => $loops) {
559-
$testsLoopLimits[$tst] = (int)($loops * $factor);
558+
$testsLoopLimits[$tst] = (int)($loops * $factor);
560559
}
561560
}
562561

@@ -625,9 +624,8 @@ function test_02_String_Concat()
625624
for ($i = 0; $i < $count; ++$i) {
626625
$s .= '- Valar dohaeris' . PHP_EOL;
627626
}
628-
$s = '';
629627
}
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));
631629
}
632630

633631
function test_03_1_String_Number_Concat()
@@ -638,7 +636,7 @@ function test_03_1_String_Number_Concat()
638636
$time_start = get_microtime();
639637
for ($i = 0; $i < $count; ++$i) {
640638
$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;
642640
}
643641
return format_result_test(get_microtime() - $time_start, $count, memory_get_usage(true));
644642
}
@@ -903,32 +901,45 @@ function test_13_Array_Fill()
903901
$X[$i][$j] = $i * $j;
904902
}
905903
}
906-
unset($X);
907904
}
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));
909906
}
910907

911-
function test_14_Array_Unset()
908+
function test_14_Array_Range()
912909
{
913910
global $testsLoopLimits, $arrayDimensionLimit;
914911

915912
$arrayTestLoopLimit = $testsLoopLimits['14_array_loop'];
916913
$time_start = get_microtime();
917914
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+
}
918922

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);
922933
}
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]);
926937
}
927-
unset($X[$i]);
938+
unset($x[$i]);
928939
}
929-
unset($X);
940+
unset($x);
930941
}
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));
932943
}
933944

934945
function test_15_Loops()
@@ -1044,7 +1055,6 @@ function test_20_Type_Conversion()
10441055
}
10451056

10461057

1047-
10481058
if ((int)$phpversion[0] >= 5) {
10491059
if (is_file('php5.inc')) {
10501060
include_once 'php5.inc';

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /