| Server IP : 213.186.33.4 / Your IP : 216.73.216.193 Web Server : Apache System : Linux webm006.cluster103.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 User : awebpaca ( 35430) PHP Version : 8.5.0 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/a/w/e/awebpaca/Dolibarr/htdocs/includes/sabre/sabre/event/tests/benchmark/ |
Upload File : |
<?php
use Sabre\Event\EventEmitter;
include __DIR__ . '/../../vendor/autoload.php';
abstract class BenchMark {
protected $startTime;
protected $iterations = 10000;
protected $totalTime;
function setUp() {
}
abstract function test();
function go() {
$this->setUp();
$this->startTime = microtime(true);
$this->test();
$this->totalTime = microtime(true) - $this->startTime;
return $this->totalTime;
}
}
class OneCallBack extends BenchMark {
protected $emitter;
protected $iterations = 100000;
function setUp() {
$this->emitter = new EventEmitter();
$this->emitter->on('foo', function() {
// NOOP
});
}
function test() {
for ($i = 0;$i < $this->iterations;$i++) {
$this->emitter->emit('foo', []);
}
}
}
class ManyCallBacks extends BenchMark {
protected $emitter;
function setUp() {
$this->emitter = new EventEmitter();
for ($i = 0;$i < 100;$i++) {
$this->emitter->on('foo', function() {
// NOOP
});
}
}
function test() {
for ($i = 0;$i < $this->iterations;$i++) {
$this->emitter->emit('foo', []);
}
}
}
class ManyPrioritizedCallBacks extends BenchMark {
protected $emitter;
function setUp() {
$this->emitter = new EventEmitter();
for ($i = 0;$i < 100;$i++) {
$this->emitter->on('foo', function() {
}, 1000 - $i);
}
}
function test() {
for ($i = 0;$i < $this->iterations;$i++) {
$this->emitter->emit('foo', []);
}
}
}
$tests = [
'OneCallBack',
'ManyCallBacks',
'ManyPrioritizedCallBacks',
];
foreach ($tests as $test) {
$testObj = new $test();
$result = $testObj->go();
echo $test . " " . $result . "\n";
}