Skip to content

Instantly share code, notes, and snippets.

@77web
Created October 31, 2018 01:31
Show Gist options
  • Save 77web/2c535aa05568e792a5935b7e04751474 to your computer and use it in GitHub Desktop.
Save 77web/2c535aa05568e792a5935b7e04751474 to your computer and use it in GitHub Desktop.
ネストforeachの配列ウチソト問題の計測用
<?php
$array1 = range(1, 1000000);
$array2 = range(1, 10);
$start = microtime(true);
$result = [];
foreach ($array1 as $value1) {
foreach ($array2 as $value2) {
$result[] = $value1 * $value2;
}
}
$end = microtime(true);
var_dump(count($result));
echo "duration:".($end - $start)."\n";
echo "memory:".memory_get_peak_usage(true)."\n";
<?php
$array2 = range(1, 1000000);
$array1 = range(1, 10);
$start = microtime(true);
$result = [];
foreach ($array1 as $value1) {
foreach ($array2 as $value2) {
$result[] = $value1 * $value2;
}
}
$end = microtime(true);
var_dump(count($result));
echo "duration:".($end - $start)."\n";
echo "memory:".memory_get_peak_usage(true)."\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment