Last active
May 26, 2020 13:02
-
-
Save kalimatas/6e8d3d455443922820074396329cfadb to your computer and use it in GitHub Desktop.
Revisions
-
Alexander Guz revised this gist
Dec 13, 2016 . 1 changed file with 15 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,41 +2,42 @@ declare(strict_types = 1); use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods; use PhpBench\Benchmark\Metadata\Annotations\Revs; require 'vendor/autoload.php'; /** * @BeforeMethods({"prepare"}) */ class PushVsMergeBench { private $a = []; private $b = []; public function prepare() { $this->a = []; $this->b = []; for ($i = 0; $i < 100000; $i++) { $this->a[] = new \stdClass(); $this->b[] = new \stdClass(); } } /** * @Revs(100) */ public function benchArrayMerge() { $this->a = array_merge($this->a, $this->b); } /** * @Revs(100) */ public function benchArrayPush() { array_push($this->a, ...$this->b); } } -
Alexander Guz created this gist
Dec 13, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ <?php declare(strict_types = 1); use PhpBench\Benchmark\Metadata\Annotations\Revs; require 'vendor/autoload.php'; class PushVsMergeBench { private function prepare() { $a = []; $b = []; for ($i = 0; $i < 100000; $i++) { $a[] = new \stdClass(); $b[] = new \stdClass(); } return [$a, $b]; } /** * @Revs(100) */ public function benchArrayMerge() { list($a, $b) = $this->prepare(); $a = array_merge($a, $b); } /** * @Revs(100) */ public function benchArrayPush() { list($a, $b) = $this->prepare(); array_push($a, ...$b); } }