Created
February 4, 2014 12:56
-
-
Save ihabunek/8803125 to your computer and use it in GitHub Desktop.
Testing a static event emitter in Evenement
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 | |
require 'vendor/autoload.php'; | |
define("LISTENERS", 100); | |
define("EVENTS", 100000); | |
printf("\n* Emitting %d events to %d listeners.\n\n", EVENTS, LISTENERS); | |
// --- Dynamic --- | |
$emitter = new Evenement\EventEmitter(); | |
$start = microtime(true); | |
for ($i = 0; $i < LISTENERS ; $i++) { | |
$emitter->on('event', function() {}); | |
} | |
$duration = microtime(true) - $start; | |
echo sprintf("Dynamic adding: %d\n", round($duration, 4)); | |
$start = microtime(true); | |
for ($i = 0; $i < EVENTS ; $i++) { | |
$emitter->emit('event', []); | |
} | |
$duration = microtime(true) - $start; | |
echo "Dynamic emitting: ", round($duration, 4), "\n"; | |
// --- Static --- | |
class Emitter { | |
use Evenement\StaticEventEmitterTrait; | |
} | |
$start = microtime(true); | |
for ($i = 0; $i < LISTENERS ; $i++) { | |
Emitter::on('event', function() {}); | |
} | |
$duration = microtime(true) - $start; | |
echo "Static adding: ", round($duration, 4), "\n"; | |
$start = microtime(true); | |
for ($i = 0; $i < EVENTS ; $i++) { | |
Emitter::emit('event', []); | |
} | |
$duration = microtime(true) - $start; | |
echo "Static emitting: ", round($duration, 4), "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment