-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimisation wildcardEmitter. added benchmark. Closes #49.
- Loading branch information
Showing
5 changed files
with
136 additions
and
16 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
theme: jekyll-theme-cayman |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,6 @@ class Version { | |
/** | ||
* Full version number | ||
*/ | ||
const VERSION = '5.0.1'; | ||
const VERSION = '5.0.2'; | ||
|
||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php declare (strict_types=1); | ||
|
||
use Sabre\Event\WildcardEmitter; | ||
|
||
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 WildcardEmitter(); | ||
$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 WildcardEmitter(); | ||
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 WildcardEmitter(); | ||
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"; | ||
|
||
} |