Browse Source

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
labels
J. King 6 years ago
parent
commit
7409520477
  1. 9
      RoboFile.php
  2. 26
      perf/perf.php

9
RoboFile.php

@ -2,11 +2,6 @@
use Robo\Result; use Robo\Result;
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
*/
class RoboFile extends \Robo\Tasks { class RoboFile extends \Robo\Tasks {
const BASE = __DIR__.\DIRECTORY_SEPARATOR; const BASE = __DIR__.\DIRECTORY_SEPARATOR;
const BASE_TEST = self::BASE."tests".\DIRECTORY_SEPARATOR; const BASE_TEST = self::BASE."tests".\DIRECTORY_SEPARATOR;
@ -47,12 +42,12 @@ class RoboFile extends \Robo\Tasks {
/** Produces a code coverage report /** Produces a code coverage report
* *
* By default this task produces an HTML-format coverage report in * 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. * arguments to this task as one would to PHPUnit.
* *
* Robo first tries to use phpdbg and will fall back to Xdebug if available. * 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 * 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 { public function coverage(array $args): Result {
// run tests with code coverage reporting enabled // run tests with code coverage reporting enabled

26
perf/perf.php

@ -17,10 +17,15 @@ $files = [
$tests = [ $tests = [
'Intl characters' => ["intl", function(string $text) { 'Intl characters' => ["intl", function(string $text) {
$i = \IntlBreakIterator::createCodePointInstance(); $i = (function($text) {
$i->setText($text); $i = \IntlBreakIterator::createCodePointInstance();
foreach ($i as $b) { $i->setText($text);
\IntlChar::chr($i->getLastCodePoint()); foreach ($i as $b) {
yield \IntlChar::chr($i->getLastCodePoint());
}
})($text);
foreach ($i as $c) {
$b = $c;
} }
}], }],
'Native characters (obj)' => ["", function(string $text) { 'Native characters (obj)' => ["", function(string $text) {
@ -36,10 +41,15 @@ $tests = [
} }
}], }],
'Intl code points' => ["intl", function(string $text) { 'Intl code points' => ["intl", function(string $text) {
$i = \IntlBreakIterator::createCodePointInstance(); $i = (function($text) {
$i->setText($text); $i = \IntlBreakIterator::createCodePointInstance();
foreach ($i as $b) { $i->setText($text);
$i->getLastCodePoint(); foreach ($i as $b) {
yield $i->getLastCodePoint();
}
})($text);
foreach ($i as $c) {
$b = $c;
} }
}], }],
'Native code points (obj)' => ["", function(string $text) { 'Native code points (obj)' => ["", function(string $text) {

Loading…
Cancel
Save