Skip to content

Zf3 evm #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 62 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
1bf4fbd
Save old code
bakura10 Sep 27, 2013
55d1de8
cleanup
bakura10 Sep 27, 2013
6aface7
Optimizing CallbackHandler for PHP 5.4
bakura10 Sep 27, 2013
ac64456
Remove useless exceptions classes
bakura10 Sep 27, 2013
ebcbdf8
Update REDME
bakura10 Oct 3, 2013
f4afaa7
Update
bakura10 Oct 5, 2013
88730fa
Change autoload
bakura10 Oct 5, 2013
28c6040
Update autoload
bakura10 Nov 1, 2013
a3c3723
Rename Callable to callable
bakura10 Nov 1, 2013
b9c394c
Add key
bakura10 Nov 1, 2013
1505f54
Fix docblock for SharedEventManager
bakura10 Nov 1, 2013
3dc99a8
Fix doc
bakura10 Nov 1, 2013
5b96e66
Make everyone return Priorityqueue
bakura10 Nov 1, 2013
98406c4
Optimize merging
bakura10 Nov 1, 2013
1e94953
Only return PriorityQueue
bakura10 Nov 1, 2013
557d0a9
Fix
bakura10 Nov 1, 2013
2499d5d
CS
bakura10 Nov 1, 2013
564faa9
Simplify API
bakura10 Nov 12, 2013
593bf89
Removing things
bakura10 Nov 12, 2013
2b69af9
Update interface
bakura10 Nov 12, 2013
68d6fbe
Trying something new
bakura10 Nov 12, 2013
cd1f53d
Sme more tests
bakura10 Nov 12, 2013
3da0a54
Fix
bakura10 Nov 12, 2013
4993201
Optimization
bakura10 Nov 12, 2013
50aaed9
Optimize more
bakura10 Nov 12, 2013
2d9e8e9
Fix shared evm
bakura10 Nov 12, 2013
379bf7f
No more dependency to stdlib
bakura10 Nov 12, 2013
ea7e77c
Replace + operator by array_merge
bakura10 Nov 13, 2013
9c1d564
Fix
bakura10 Nov 13, 2013
a61635e
Various cleanings and optimizations
bakura10 Nov 13, 2013
e4e3b38
Fix things
bakura10 Nov 13, 2013
b011fc8
Squizzing every little bit
bakura10 Nov 13, 2013
c783e9e
Fix benchmark
bakura10 Nov 13, 2013
e7ca7b2
Changes
bakura10 Nov 13, 2013
1f9ad43
Optimizations
bakura10 Nov 13, 2013
606bfe2
Remove useless isset
bakura10 Nov 14, 2013
f7ca865
Fix clearing
bakura10 Nov 14, 2013
5df8aac
Foo
bakura10 Nov 14, 2013
88ee872
Sort numerically
bakura10 Nov 15, 2013
0d8bd8c
Experimental optimizsations
marc-mabe Nov 15, 2013
1e66ecf
Sort numerically
bakura10 Nov 15, 2013
efa160b
EVM optimizations
marc-mabe Nov 15, 2013
914ac01
simple EVM benchmark script
marc-mabe Nov 15, 2013
caf7b97
Merge
marc-mabe Nov 15, 2013
e663a4e
fix conflicts
bakura10 Nov 15, 2013
9f3831c
Fix CS
bakura10 Nov 15, 2013
e412a6a
fixed SharedEventManager::getListeners() and make SharedEventManager:…
marc-mabe Nov 18, 2013
6b1e804
Merge pull request #3 from marc-mabe/zf3-evm-opt
bakura10 Nov 18, 2013
d28b43e
Update benchmark
bakura10 Nov 19, 2013
07a3b9b
Add tests
bakura10 Nov 19, 2013
5d45e50
Merge branch 'zf3-evm' of https://github.com/bakura10/zf2 into zf3-evm
bakura10 Nov 19, 2013
070704d
Add more tests
bakura10 Nov 19, 2013
4176839
Add athletic
bakura10 May 15, 2014
8183c7d
Add benchmarks
bakura10 May 15, 2014
3ce8338
Improve SEM merging by 10%
bakura10 May 15, 2014
0879030
Do not need to sort twice
bakura10 May 15, 2014
1083e75
Add fast event manager
bakura10 May 15, 2014
01b2975
make sure callback is called
bakura10 May 15, 2014
ac3518c
Refactor for the FastEventManager
bakura10 May 15, 2014
0ad6718
Clean
bakura10 May 15, 2014
2db8e57
Optimization
bakura10 May 16, 2014
b2ab473
Add tests
bakura10 May 17, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions benchmarks/ZendBenchmark/EventManager/AttachBenchmark.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/

namespace ZendBenchmark\EventManager;

use Athletic\AthleticEvent;
use Zend\EventManager\EventManager;

class AttachBenchmark extends AthleticEvent
{
/**
* @var EventManager
*/
protected $eventManager;

public function classSetUp()
{
$this->eventManager = new EventManager();
}

/**
* @iterations 50
*/
public function attachOneThousandListeners()
{
for ($i = 0 ; $i != 1000 ; ++$i) {
$this->eventManager->attach('eventName', function() {;});
}
}
}
86 changes: 86 additions & 0 deletions benchmarks/ZendBenchmark/EventManager/TriggerEvmBenchmark.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/

namespace ZendBenchmark\EventManager;

use Athletic\AthleticEvent;
use Zend\EventManager\EventManager;
use Zend\EventManager\SharedEventManager;

class TriggerEvmBenchmark extends AthleticEvent
{
/**
* @var EventManager
*/
protected $eventManager;

public function classSetUp()
{
$this->eventManager = new EventManager();

// Add one hundred listeners to two different events with random priorities
for ($i = 0 ; $i != 100 ; ++$i) {
$this->eventManager->attach('eventName1', function() {}, rand(0, 100));
$this->eventManager->attach('eventName2', function() {}, rand(0, 100));
}

// Attach also fifty listeners to the wildcard
for ($i = 0 ; $i != 10 ; ++$i) {
$this->eventManager->attach('*', function() {}, rand(0, 100));
}
}

/**
* @iterations 50
*/
public function triggerEventOneTimeWithoutSharedManager()
{
$this->eventManager->trigger('eventName1');
}

/**
* @iterations 50
*/
public function triggerEventOneTimeWithEmptySharedManager()
{
$this->eventManager->setSharedManager(new SharedEventManager());
$this->eventManager->trigger('eventName1');
}

/**
* @iterations 50
*/
public function triggerEventTenTimesWithoutSharedManager()
{
for ($i = 0 ; $i !== 10 ; ++$i) {
$this->eventManager->trigger('eventName1');
}
}

/**
* @iterations 50
*/
public function triggerEventTenTimesWithEmptySharedManager()
{
$this->eventManager->setSharedManager(new SharedEventManager());

for ($i = 0 ; $i !== 10 ; ++$i) {
$this->eventManager->trigger('eventName1');
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/

namespace ZendBenchmark\EventManager;

use Athletic\AthleticEvent;
use Zend\EventManager\EventManager;
use Zend\EventManager\SharedEventManager;

class TriggerEvmWithSemBenchmark extends AthleticEvent
{
/**
* @var EventManager
*/
protected $eventManager;

/**
* @var SharedEventManager
*/
protected $sharedManager;

public function classSetUp()
{
$this->eventManager = new EventManager();
$this->sharedManager = new SharedEventManager();

$this->eventManager->setIdentifiers(['identifier1', 'identifier2']);
$this->eventManager->setSharedManager($this->sharedManager);

// Add fifty listeners to two different events with random priorities in the EVM and SEM
for ($i = 0 ; $i != 50 ; ++$i) {
$this->eventManager->attach('eventName1', function() {}, rand(0, 100));
$this->eventManager->attach('eventName2', function() {}, rand(0, 100));

$this->sharedManager->attach('identifier1', 'eventName1', function() {}, rand(0, 100));
$this->sharedManager->attach('identifier2', 'eventName1', function() {}, rand(0, 100));
$this->sharedManager->attach('identifier3', 'eventName1', function() {}, rand(0, 100));
}

// Attach also fifty listeners to the wildcard
for ($i = 0 ; $i != 10 ; ++$i) {
$this->eventManager->attach('*', function() {}, rand(0, 100));
$this->sharedManager->attach('*', 'eventName1', function() {}, rand(0, 100));
$this->sharedManager->attach('identifier1', '*', function() {}, rand(0, 100));
$this->sharedManager->attach('*', '*', function() {}, rand(0, 100));
}
}

/**
* @iterations 50
*/
public function triggerEventOneTime()
{
$this->eventManager->trigger('eventName1');
}

/**
* @iterations 50
*/
public function triggerEventTenTimes()
{
for ($i = 0 ; $i !== 10 ; ++$i) {
$this->eventManager->trigger('eventName1');
}
}
}
7 changes: 7 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"php": ">=5.3.3"
},
"require-dev": {
"athletic/athletic": "0.1.7",
"doctrine/annotations": ">=1.0",
"ircmaxell/random-lib": "dev-master",
"ircmaxell/security-lib": "dev-master",
Expand All @@ -29,6 +30,12 @@
"autoload": {
"psr-0": {
"Zend\\": "library/"

}
},
"autoload-dev": {
"psr-0": {
"ZendBenchmark\\": "benchmarks/"
}
},
"bin": [
Expand Down
61 changes: 61 additions & 0 deletions demos/bench-evm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

function emptyFunc() {}

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

$numberOfListeners = 100;
$numberOfTriggers = 1000;
$totalTimeStart = microtime(true);;


$eventManager = new \Zend\EventManager\EventManager(array('myid1', 'myid2'));

echo "Attach {$numberOfListeners} listeners: ";
$memStart = memory_get_usage();
$timeStart = microtime(true);
for ($i = 0; $i < $numberOfListeners; ++$i) {
$eventManager->attach('event', 'emptyFunc', $i % 10);
}
$timeEnd = microtime(true);
$memEnd = memory_get_usage(true);
printf("time=%f, mem=%d\n", $timeEnd - $timeStart, $memEnd - $memStart);


echo "Triggers {$numberOfTriggers} events: ";
$memStart = memory_get_usage();
$timeStart = microtime(true);
for ($i = 0; $i < $numberOfListeners; ++$i) {
$eventManager->trigger('event');
}
$timeEnd = microtime(true);
$memEnd = memory_get_usage(true);
printf("time=%f, mem=%d\n", $timeEnd - $timeStart, $memEnd - $memStart);


$sharedManager = new \Zend\EventManager\SharedEventManager();
$eventManager->setSharedManager($sharedManager);

echo "Attach {$numberOfListeners} shared listeners: ";
$memStart = memory_get_usage();
$timeStart = microtime(true);
for ($i = 0; $i < $numberOfListeners; ++$i) {
$sharedManager->attach('myid1', 'event', 'emptyFunc', $i % 10);
}
$timeEnd = microtime(true);
$memEnd = memory_get_usage(true);
printf("time=%f, mem=%d\n", $timeEnd - $timeStart, $memEnd - $memStart);


echo "Triggers {$numberOfTriggers} events: ";
$memStart = memory_get_usage();
$timeStart = microtime(true);
for ($i = 0; $i < $numberOfListeners; ++$i) {
$eventManager->trigger('event');
}
$timeEnd = microtime(true);
$memEnd = memory_get_usage(true);
printf("time=%f, mem=%d\n", $timeEnd - $timeStart, $memEnd - $memStart);


printf("\nTotal: time=%f, mem=%d\n", microtime(true) - $totalTimeStart, memory_get_peak_usage(true));
61 changes: 61 additions & 0 deletions demos/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

function emptyFunc() {}

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

$numberOfListeners = 100;
$numberOfTriggers = 1000;
$totalTimeStart = microtime(true);


$eventManager = new \Zend\EventManager\EventManager(array('myid'));

echo "Attach {$numberOfListeners} listeners: ";
$memStart = memory_get_usage();
$timeStart = microtime(true);
for ($i = 0; $i < $numberOfListeners; ++$i) {
$eventManager->attach('event', 'emptyFunc', $i);
}
$timeEnd = microtime(true);
$memEnd = memory_get_usage(true);
printf("time=%f, mem=%d<br>", $timeEnd - $timeStart, $memEnd - $memStart);


echo "Triggers {$numberOfTriggers} events: ";
$memStart = memory_get_usage();
$timeStart = microtime(true);
for ($i = 0; $i < $numberOfListeners; ++$i) {
$eventManager->trigger('event');
}
$timeEnd = microtime(true);
$memEnd = memory_get_usage(true);
printf("time=%f, mem=%d<br>", $timeEnd - $timeStart, $memEnd - $memStart);


$sharedManager = new \Zend\EventManager\SharedEventManager();
$eventManager->setSharedManager($sharedManager);

echo "Attach {$numberOfListeners} shared listeners: ";
$memStart = memory_get_usage();
$timeStart = microtime(true);
for ($i = 0; $i < $numberOfListeners; ++$i) {
$sharedManager->attach('myid', 'event', 'emptyFunc', $i);
}
$timeEnd = microtime(true);
$memEnd = memory_get_usage(true);
printf("time=%f, mem=%d<br>", $timeEnd - $timeStart, $memEnd - $memStart);


echo "Triggers {$numberOfTriggers} events: ";
$memStart = memory_get_usage();
$timeStart = microtime(true);
for ($i = 0; $i < $numberOfListeners; ++$i) {
$eventManager->trigger('event');
}
$timeEnd = microtime(true);
$memEnd = memory_get_usage(true);
printf("time=%f, mem=%d<br>", $timeEnd - $timeStart, $memEnd - $memStart);


printf("<br>Total: time=%f, mem=%d\n", microtime(true) - $totalTimeStart, memory_get_peak_usage(true));
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function stopPropagation($flag = true)
*
* @return bool
*/
public function propagationIsStopped()
public function isPropagationStopped()
{
return false;
}
Expand Down
21 changes: 1 addition & 20 deletions library/Zend/EventManager/AbstractListenerAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,7 @@

namespace Zend\EventManager;


/**
* Abstract aggregate listener
*/
abstract class AbstractListenerAggregate implements ListenerAggregateInterface
{
/**
* @var \Zend\Stdlib\CallbackHandler[]
*/
protected $listeners = array();

/**
* {@inheritDoc}
*/
public function detach(EventManagerInterface $events)
{
foreach ($this->listeners as $index => $callback) {
if ($events->detach($callback)) {
unset($this->listeners[$index]);
}
}
}
use ListenerAggregateTrait;
}
Loading