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;
/**
* 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

26
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) {

Loading…
Cancel
Save