PHP Classes

File: vendor/evenement/evenement/examples/benchmark-remove-listener-once.php

Recommend this page to a friend!
  Classes of butani kartik   PHP WebSockets Server Example   vendor/evenement/evenement/examples/benchmark-remove-listener-once.php   Download  
File: vendor/evenement/evenement/examples/benchmark-remove-listener-once.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP WebSockets Server Example
Example to interact with a server using WebSockets
Author: By
Last change:
Date: 3 years ago
Size: 1,021 bytes
 

Contents

Class file image Download
<?php declare(strict_types=1);

/*
 * This file is part of Evenement.
 *
 * (c) Igor Wiedler <igor@wiedler.ch>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

ini_set('memory_limit', '512M');

const
ITERATIONS = 100000;

use
Evenement\EventEmitter;

require
__DIR__.'/../vendor/autoload.php';

$emitter = new EventEmitter();

$listeners = [];
for (
$i = 0; $i < ITERATIONS; $i++) {
   
$listeners[] = function ($a, $b, $c) {};
}

$start = microtime(true);
foreach (
$listeners as $listener) {
   
$emitter->once('event', $listener);
}
$time = microtime(true) - $start;
echo
'Adding ', number_format(ITERATIONS), ' once listeners took: ', number_format($time, 2), 's', PHP_EOL;

$start = microtime(true);
foreach (
$listeners as $listener) {
   
$emitter->removeListener('event', $listener);
}
$time = microtime(true) - $start;
echo
'Removing ', number_format(ITERATIONS), ' once listeners took: ', number_format($time, 2), 's', PHP_EOL;