Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In test with 100000 cycles i had such results:</p> <pre><code>bin/php-test CloneVsNew [============================================================&gt;] 100000 u | 4399 u/s | Est: 0.0 s | Mem: 342,74 KB | Max: 367,1 KB [============================================================&gt;] 100000 u | 4105 u/s | Est: 0.0 s | Mem: 343,14 KB | Max: 367,1 KB New 1,282884 sec. Clone 1,107343 sec. </code></pre> <p>So, seems clone slightly more efficient way to copy objects. Here is test code:</p> <pre><code>class CloneVsNew extends TestApplication { final public static function run() { $repeats = 100000; $bar = new CliProgressBar($repeats); for ($i = 0; $i &lt;= $repeats; ++$i) { Timer::start(); $myobj1=new \stdClass(); $myobj2=new \stdClass(); $myobj3=new \stdClass(); $myobj4=new \stdClass(); Timer::stop(); $bar-&gt;update($i); } self::addResult('New', Timer::get()); $bar = new CliProgressBar($repeats); Timer::reset(); for ($i = 0; $i &lt;= $repeats; ++$i) { Timer::start(); $myobj1 = new \stdClass(); $myobj2 = clone $myobj1; $myobj3 = clone $myobj1; $myobj4 = clone $myobj1; Timer::stop(); $bar-&gt;update($i); } self::addResult('Clone', Timer::get()); } } </code></pre> <p>Tested on:</p> <pre><code>php -v PHP 5.4.17-1~dotdeb.1 (cli) (built: Jul 6 2013 16:20:31) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans </code></pre> <p>Other php versions can show other results.</p> <p><strong>Update:</strong></p> <p>For the test used <a href="https://github.com/nafigator/php-bench" rel="nofollow">php-bench</a> tool.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload