benchmark-emit-once.php 729 B

123456789101112131415161718192021222324252627282930
  1. <?php declare(strict_types=1);
  2. /*
  3. * This file is part of Evenement.
  4. *
  5. * (c) Igor Wiedler <igor@wiedler.ch>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. ini_set('memory_limit', '512M');
  11. const ITERATIONS = 100000;
  12. use Evenement\EventEmitter;
  13. require __DIR__.'/../vendor/autoload.php';
  14. $emitter = new EventEmitter();
  15. for ($i = 0; $i < ITERATIONS; $i++) {
  16. $emitter->once('event', function ($a, $b, $c) {});
  17. }
  18. $start = microtime(true);
  19. $emitter->emit('event', [1, 2, 3]);
  20. $time = microtime(true) - $start;
  21. echo 'Emitting one event to ', number_format(ITERATIONS), ' once listeners took: ', number_format($time, 2), 's', PHP_EOL;