Skip to content

Instantly share code, notes, and snippets.

@kelunik
Created August 16, 2017 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kelunik/c3e68e973e514f175ef8f9f41a9f0573 to your computer and use it in GitHub Desktop.
Save kelunik/c3e68e973e514f175ef8f9f41a9f0573 to your computer and use it in GitHub Desktop.
<?php
# Benchmark for the cost of returning a new promise from then() for coroutines.
#
# - composer install
# - php bench.php
# - vi vendor/amphp/amp/lib/functions.php # remove 'done' branch --> https://git.io/v7NWW
# - php bench.php
require __DIR__ . "/vendor/autoload.php";
$start = microtime(1);
Amp\Loop::run(function () {
for ($i = 0; $i < 300000; $i++) {
$promise = new React\Promise\Promise(function ($resolve, $reject) {
$resolve(1);
});
yield $promise;
}
});
print "Completed in " . (microtime(1) - $start) . " seconds." . PHP_EOL;
{
"name": "kelunik/promise-performance",
"require": {
"amphp/amp": "^2.0",
"react/promise": "^2.5"
},
"authors": [
{
"name": "Niklas Keller",
"email": "me@kelunik.com"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment