Created
August 16, 2017 15:00
-
-
Save kelunik/c3e68e973e514f175ef8f9f41a9f0573 to your computer and use it in GitHub Desktop.
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
<?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; |
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
{ | |
"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