From 7409520477d3f9c369137d2fa0867bc936ca8462 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Wed, 1 Aug 2018 14:51:05 -0400 Subject: [PATCH] Make performance comparison fairer The Intl tests avoided one mission user-function calls by doing a simple loop, something unlikely to be used in real-world situations; wrapping the test in a generator adds the overhead one would expect to have, making the pure PHP implementation much more competitive --- RoboFile.php | 9 ++------- perf/perf.php | 26 ++++++++++++++++++-------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/RoboFile.php b/RoboFile.php index 068ff28..7897ce5 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -2,11 +2,6 @@ use Robo\Result; -/** - * This is project's console commands configuration for Robo task runner. - * - * @see http://robo.li/ - */ class RoboFile extends \Robo\Tasks { const BASE = __DIR__.\DIRECTORY_SEPARATOR; const BASE_TEST = self::BASE."tests".\DIRECTORY_SEPARATOR; @@ -47,12 +42,12 @@ class RoboFile extends \Robo\Tasks { /** Produces a code coverage report * * By default this task produces an HTML-format coverage report in - * arsse/tests/coverage/. Additional reports may be produced by passing + * tests/coverage/. Additional reports may be produced by passing * arguments to this task as one would to PHPUnit. * * Robo first tries to use phpdbg and will fall back to Xdebug if available. * Because Xdebug slows down non-coverage tasks, however, phpdbg is highly - * recommanded is debugging facilities are not otherwise needed. + * recommended if debugging facilities are not otherwise needed. */ public function coverage(array $args): Result { // run tests with code coverage reporting enabled diff --git a/perf/perf.php b/perf/perf.php index 601c490..978a2e0 100644 --- a/perf/perf.php +++ b/perf/perf.php @@ -17,10 +17,15 @@ $files = [ $tests = [ 'Intl characters' => ["intl", function(string $text) { - $i = \IntlBreakIterator::createCodePointInstance(); - $i->setText($text); - foreach ($i as $b) { - \IntlChar::chr($i->getLastCodePoint()); + $i = (function($text) { + $i = \IntlBreakIterator::createCodePointInstance(); + $i->setText($text); + foreach ($i as $b) { + yield \IntlChar::chr($i->getLastCodePoint()); + } + })($text); + foreach ($i as $c) { + $b = $c; } }], 'Native characters (obj)' => ["", function(string $text) { @@ -36,10 +41,15 @@ $tests = [ } }], 'Intl code points' => ["intl", function(string $text) { - $i = \IntlBreakIterator::createCodePointInstance(); - $i->setText($text); - foreach ($i as $b) { - $i->getLastCodePoint(); + $i = (function($text) { + $i = \IntlBreakIterator::createCodePointInstance(); + $i->setText($text); + foreach ($i as $b) { + yield $i->getLastCodePoint(); + } + })($text); + foreach ($i as $c) { + $b = $c; } }], 'Native code points (obj)' => ["", function(string $text) {