-
-
Notifications
You must be signed in to change notification settings - Fork 132
Added enhanced test-memory.php, originally from react/react #59
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
480228f
Added enhanced test-memory.php, originally from react/react
WyriHaximus 2cacaa3
Added usage
WyriHaximus 27ce078
Applied argument suggestions by @clue from https://github.com/reactph…
WyriHaximus 0835fc1
Updated autoloading path and renamed to 95-benchmark-memory.php
WyriHaximus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,67 @@ | ||
<?php | ||
|
||
/** | ||
* Run the script indefinitely seconds with the loop from the factory and report every 2 seconds: | ||
* php test-memory.php | ||
* Run the script for 30 seconds with the stream_select loop and report every 10 seconds: | ||
* php test-memory.php -t 30 -l StreamSelect -r 10 | ||
*/ | ||
|
||
use React\EventLoop\Factory; | ||
use React\EventLoop\LoopInterface; | ||
use React\EventLoop\Timer\TimerInterface; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$args = getopt('t:l:r:'); | ||
$t = isset($args['t']) ? (int)$args['t'] : 0; | ||
$loop = isset($args['l']) && class_exists('React\EventLoop\\' . $args['l'] . 'Loop') ? 'React\EventLoop\\' . $args['l'] . 'Loop' : Factory::create(); | ||
|
||
if (!($loop instanceof LoopInterface)) { | ||
$loop = new $loop(); | ||
} | ||
|
||
$r = isset($args['r']) ? (int)$args['r'] : 2; | ||
|
||
$runs = 0; | ||
|
||
if (5 < $t) { | ||
$loop->addTimer($t, function (TimerInterface $timer) { | ||
$timer->getLoop()->stop(); | ||
}); | ||
|
||
} | ||
|
||
$loop->addPeriodicTimer(0.001, function () use (&$runs, $loop) { | ||
$runs++; | ||
|
||
$loop->addPeriodicTimer(1, function (TimerInterface $timer) { | ||
$timer->cancel(); | ||
}); | ||
}); | ||
|
||
$loop->addPeriodicTimer($r, function () use (&$runs) { | ||
$kmem = round(memory_get_usage() / 1024); | ||
$kmemReal = round(memory_get_usage(true) / 1024); | ||
echo "Runs:\t\t\t$runs\n"; | ||
echo "Memory (internal):\t$kmem KiB\n"; | ||
echo "Memory (real):\t\t$kmemReal KiB\n"; | ||
echo str_repeat('-', 50), "\n"; | ||
}); | ||
|
||
echo "PHP Version:\t\t", phpversion(), "\n"; | ||
echo "Loop\t\t\t", get_class($loop), "\n"; | ||
echo "Time\t\t\t", date('r'), "\n"; | ||
|
||
echo str_repeat('-', 50), "\n"; | ||
|
||
$beginTime = time(); | ||
$loop->run(); | ||
$endTime = time(); | ||
$timeTaken = $endTime - $beginTime; | ||
|
||
echo "PHP Version:\t\t", phpversion(), "\n"; | ||
echo "Loop\t\t\t", get_class($loop), "\n"; | ||
echo "Time\t\t\t", date('r'), "\n"; | ||
echo "Time taken\t\t", $timeTaken, " seconds\n"; | ||
echo "Runs per second\t\t", round($runs / $timeTaken), "\n"; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why that instead of just adding the
new
above?