From 480228fe16462a0b66d9e18ca5f66a5838c0ccc6 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Sun, 13 Nov 2016 22:19:21 +0100 Subject: [PATCH 1/4] Added enhanced test-memory.php, originally from react/react --- examples/test-memory.php | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 examples/test-memory.php diff --git a/examples/test-memory.php b/examples/test-memory.php new file mode 100644 index 00000000..6d95a336 --- /dev/null +++ b/examples/test-memory.php @@ -0,0 +1,54 @@ +addTimer((int)$argv[1], function (TimerInterface $timer) { + $timer->getLoop()->stop(); + }); + +} + +$loop->addPeriodicTimer(0.001, function () use (&$i, $loop) { + $i++; + + $loop->addPeriodicTimer(1, function (TimerInterface $timer) { + $timer->cancel(); + }); +}); + +$loop->addPeriodicTimer(2, function () use (&$i) { + $kmem = round(memory_get_usage() / 1024); + $kmemReal = round(memory_get_usage(true) / 1024); + echo "Runs:\t\t\t$i\n"; + echo "Memory (internal):\t$kmem KiB\n"; + echo "Memory (real):\t\t$kmemReal KiB\n"; + echo str_repeat('-', 50), "\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 "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($i / $timeTaken), "\n"; From 2cacaa3701ae1d1f3aca63f8c9e36e007a720961 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Sun, 13 Nov 2016 22:25:30 +0100 Subject: [PATCH 2/4] Added usage --- examples/test-memory.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/test-memory.php b/examples/test-memory.php index 6d95a336..3c36b33a 100644 --- a/examples/test-memory.php +++ b/examples/test-memory.php @@ -1,5 +1,11 @@ Date: Mon, 14 Nov 2016 13:29:12 +0100 Subject: [PATCH 3/4] Applied argument suggestions by @clue from https://github.com/reactphp/event-loop/pull/59#issuecomment-260259139 --- examples/test-memory.php | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/examples/test-memory.php b/examples/test-memory.php index 3c36b33a..36cf5ba2 100644 --- a/examples/test-memory.php +++ b/examples/test-memory.php @@ -1,49 +1,55 @@ addTimer((int)$argv[1], function (TimerInterface $timer) { +if (5 < $t) { + $loop->addTimer($t, function (TimerInterface $timer) { $timer->getLoop()->stop(); }); } -$loop->addPeriodicTimer(0.001, function () use (&$i, $loop) { - $i++; +$loop->addPeriodicTimer(0.001, function () use (&$runs, $loop) { + $runs++; $loop->addPeriodicTimer(1, function (TimerInterface $timer) { $timer->cancel(); }); }); -$loop->addPeriodicTimer(2, function () use (&$i) { +$loop->addPeriodicTimer($r, function () use (&$runs) { $kmem = round(memory_get_usage() / 1024); $kmemReal = round(memory_get_usage(true) / 1024); - echo "Runs:\t\t\t$i\n"; + 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"; @@ -54,7 +60,8 @@ $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($i / $timeTaken), "\n"; +echo "Runs per second\t\t", round($runs / $timeTaken), "\n"; From 0835fc1beb38142bbf754d0d2ad00aebcdbe33f1 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Wed, 26 Jul 2017 09:32:17 +0200 Subject: [PATCH 4/4] Updated autoloading path and renamed to 95-benchmark-memory.php --- examples/{test-memory.php => 95-benchmark-memory.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename examples/{test-memory.php => 95-benchmark-memory.php} (97%) diff --git a/examples/test-memory.php b/examples/95-benchmark-memory.php similarity index 97% rename from examples/test-memory.php rename to examples/95-benchmark-memory.php index 36cf5ba2..7720aca1 100644 --- a/examples/test-memory.php +++ b/examples/95-benchmark-memory.php @@ -11,7 +11,7 @@ use React\EventLoop\LoopInterface; use React\EventLoop\Timer\TimerInterface; -require __DIR__.'/vendor/autoload.php'; +require __DIR__ . '/../vendor/autoload.php'; $args = getopt('t:l:r:'); $t = isset($args['t']) ? (int)$args['t'] : 0; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy