Created
April 27, 2015 18:55
-
-
Save harentius/ed906eb962b17ac237f1 to your computer and use it in GitHub Desktop.
Prototype
This file contains 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 characters
<?php | |
namespace DesignPatterns\Creational\Prototype; | |
require_once '../../vendor/autoload.php'; | |
$fooPrototype = new FooBookPrototype(); | |
// now lets say we need 10,000 books of foo and 5,000 of bar ... | |
$maxObjects = 6000000; | |
$time = microtime(true); | |
for ($i = 0; $i < $maxObjects; $i++) { | |
$book = new FooBookPrototype(); | |
$book->setTitle('Foo Book No ' . $i); | |
} | |
printf("Creating %d new objects... %f s\n", $maxObjects, microtime(true) - $time); | |
$time = microtime(true); | |
for ($i = 0; $i < $maxObjects; $i++) { | |
$book = clone $fooPrototype; | |
$book->setTitle('Foo Book No ' . $i); | |
} | |
printf("Cloning %d objects........ %f s\n", $maxObjects, microtime(true) - $time); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment