Skip to content

Instantly share code, notes, and snippets.

@oelmekki
Created July 1, 2009 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oelmekki/138722 to your computer and use it in GitHub Desktop.
Save oelmekki/138722 to your computer and use it in GitHub Desktop.
<?php
class Foo
{
public function __construct()
{
sleep( 1 );
}
}
/**
* With new
*/
$collec = array();
$first_start = time();
for ( $i = 0; $i < 10; $i++ )
{
$collec[] = new Foo();
}
$first_stop = time();
echo $first_stop - $first_start . "\n";
/**
* With clone
*/
$collec = array();
$second_start = time();
$carbon = new Foo();
for ( $i = 0; $i < 10; $i++ )
{
$collec[] = clone $carbon;
}
$second_stop = time();
echo $second_stop - $second_start . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment