Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@harentius
Created April 27, 2015 18:55
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 harentius/ed906eb962b17ac237f1 to your computer and use it in GitHub Desktop.
Save harentius/ed906eb962b17ac237f1 to your computer and use it in GitHub Desktop.
Prototype
<?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