Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require_once(__DIR__.'/autoload.php');
- function repeatMerge($array, $rCount)
- {
- return call_user_func_array('array_merge', array_fill(1, $rCount, $array));
- }
- function repeatLoops($array, $rCount)
- {
- $result = [];
- $eCount = count($array);
- for($j=0; $j<$rCount; $j++)
- {
- for($i=0; $i<$eCount; $i++)
- {
- $result[]=$array[$i];
- }
- }
- return $result;
- }
- function arr2str2arr($array, $rCount)
- {
- return explode(',', ltrim(str_repeat(','. implode(',', $array), $rCount), ','));;
- }
- set_time_limit(0);
- $measure = new \Benchmark\Measure;
- $array = range(1, 1000);
- $count = 1000;
- $x = $measure->benchmarkTime('repeatMerge', [$array, $count], (int)1E2);
- $y = $measure->benchmarkTime('repeatLoops', [$array, $count], (int)1E2);
- $z = $measure->benchmarkTime('arr2str2arr', [$array, $count], (int)1E2);
- var_dump($x, $y, $z);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement