-
Notifications
You must be signed in to change notification settings - Fork 2
Performance
Marc J. Schmidt edited this page Apr 15, 2016
·
3 revisions
Geshi and KeyLighter were tested with that simple script. It's not piece of an art but it works.
$files = [
'very small' => 'MqttClient.php',
'small' => 'XmlDeserializer.php',
'medium' => 'BaseYii.php',
'large' => 'XmppClient.php',
'very large' => 'geshi.php',
];
$tests = [
'KeyLighter' => function($file) {
$content = file_get_contents($file);
$parser = new \Kadet\Highlighter\Language\Php();
$out = new \Kadet\Highlighter\Formatter\HtmlFormatter();
$start = microtime(true);
$out->format($parser->parse($content));
return (microtime(true) - $start);
},
'geshi' => function($file) {
$geshi = new Geshi(file_get_contents($file), 'php');
$start = microtime(true);
$geshi->parse_code();
return (microtime(true) - $start);
}
];
$no = 10;
$results = [];
foreach ($tests as $name => $test) {
$results[$name] = [];
echo "\033[1;34m{$name}\033[0;21m:".PHP_EOL;
foreach ($files as $file => $path) {
$results[$name][$file] = [];
echo " * \033[1;33m{$file}\033[0;21m:".PHP_EOL;
$start = microtime(true);
for($i = 0; $i < $no + 1; $i++) {
$time = $test($path)*1000;
echo " - \033[1;92m".number_format($time, 2)."\033[0;21mms".PHP_EOL;
$results[$name][$file][] = $time;
usleep(500000);
}
sort($results[$name][$file]);
array_pop($results[$name][$file]);
}
}
$avg = [];
foreach($results as $name => $file) {
$avg[$name] = [];
foreach($file as $q => $result) {
$avg[$name][$q] = [
'min' => min($result),
'max' => max($result),
'avg' => array_sum($result)/$no
];
}
}
echo PHP_EOL.PHP_EOL;
echo PHP_VERSION." \033[1;34mRESULTS: \033[0;21m".PHP_EOL;
$max = max(array_map(function($a) { return strlen($a); }, array_keys($tests)));
foreach (array_keys($files) as $file) {
echo "\033[1;92m{$file}\033[0;21m:".PHP_EOL;
$avgs = [];
foreach (array_keys($tests) as $test) {
echo " * \033[1;33m".str_pad($test, $max)."\033[0;21m ";
$result = $avg[$test][$file];
$avgs[$test] = $result['avg'];
echo "\033[1;92mmin\033[0;21m: ".number_format($result['min'], 2).'ms ';
echo "\033[1;92mavg\033[0;21m: ".number_format($result['avg'], 2).'ms ';
echo "\033[1;92mmax\033[0;21m: ".number_format($result['max'], 2).'ms ';
echo PHP_EOL;
}
echo PHP_EOL;
asort($avgs);
reset($avgs);
$fast = ['key' => key($avgs), 'value' => current($avgs)];
end($avgs);
$slow = ['key' => key($avgs), 'value' => current($avgs)];
echo " \033[1;33m{$fast['key']}\033[0;21m was about \033[1;92m".number_format($slow['value']/$fast['value'], 2)."x\033[0m faster than ".$slow['key'];
echo PHP_EOL;
}
File | Source | Lines of Code | Size [kB] |
---|---|---|---|
very small | MqttClient.php | 48 | 1.26 |
small | XmlDeserializer.php | 209 | 6.65 |
medium | BaseYii.php | 537 | 21.32 |
large | XmppClient.php | 1015 | 31.14 |
very large | geshi.php | 4789 | 205.26 |
very small:
* KeyLighter min: 16.23ms avg: 17.80ms max: 20.59ms
* geshi min: 76.29ms avg: 79.92ms max: 85.92ms
KeyLighter was about 4.49x faster than geshi
small:
* KeyLighter min: 100.69ms avg: 105.23ms max: 112.40ms
* geshi min: 119.92ms avg: 126.00ms max: 132.76ms
KeyLighter was about 1.20x faster than geshi
medium:
* KeyLighter min: 264.60ms avg: 277.14ms max: 294.51ms
* geshi min: 200.50ms avg: 203.39ms max: 208.92ms
geshi was about 1.36x faster than KeyLighter
large:
* KeyLighter min: 631.05ms avg: 650.03ms max: 663.67ms
* geshi min: 421.63ms avg: 426.48ms max: 431.97ms
geshi was about 1.52x faster than KeyLighter
very large:
* KeyLighter min: 3,754.22ms avg: 3,850.14ms max: 3,882.88ms
* geshi min: 3,668.49ms avg: 3,699.67ms max: 3,725.26ms
geshi was about 1.04x faster than KeyLighter
very small:
* KeyLighter min: 8.92ms avg: 10.15ms max: 13.90ms
* geshi min: 67.53ms avg: 75.02ms max: 89.20ms
KeyLighter was about 7.39x faster than geshi
small:
* KeyLighter min: 52.20ms avg: 56.63ms max: 63.72ms
* geshi min: 109.63ms avg: 116.31ms max: 120.66ms
KeyLighter was about 2.05x faster than geshi
medium:
* KeyLighter min: 159.55ms avg: 172.65ms max: 194.55ms
* geshi min: 179.64ms avg: 187.03ms max: 194.61ms
KeyLighter was about 1.08x faster than geshi
large:
* KeyLighter min: 375.01ms avg: 396.49ms max: 415.24ms
* geshi min: 380.84ms avg: 387.94ms max: 394.04ms
geshi was about 1.02x faster than KeyLighter
very large:
* KeyLighter min: 2,352.61ms avg: 2,443.81ms max: 2,485.43ms
* geshi min: 3,236.37ms avg: 3,254.19ms max: 3,268.30ms
KeyLighter was about 1.33x faster than geshi
very small:
* KeyLighter min: 8.54ms avg: 9.49ms max: 11.34ms
* geshi min: 65.25ms avg: 70.36ms max: 78.21ms
KeyLighter was about 7.41x faster than geshi
small:
* KeyLighter min: 48.70ms avg: 53.23ms max: 56.63ms
* geshi min: 108.43ms avg: 115.66ms max: 123.82ms
KeyLighter was about 2.17x faster than geshi
medium:
* KeyLighter min: 149.39ms avg: 164.09ms max: 184.79ms
* geshi min: 177.15ms avg: 184.18ms max: 190.21ms
KeyLighter was about 1.12x faster than geshi
large:
* KeyLighter min: 371.71ms avg: 387.20ms max: 403.47ms
* geshi min: 382.20ms avg: 386.91ms max: 393.09ms
geshi was about 1.00x faster than KeyLighter
very large:
* KeyLighter min: 2,277.11ms avg: 2,386.44ms max: 2,498.57ms
* geshi min: 3,244.93ms avg: 3,266.72ms max: 3,295.73ms
KeyLighter was about 1.37x faster than geshi
very small:
* KeyLighter min: 3.40ms avg: 3.85ms max: 4.61ms
* geshi min: 26.52ms avg: 29.16ms max: 33.10ms
KeyLighter was about 7.58x faster than geshi
small:
* KeyLighter min: 18.15ms avg: 21.94ms max: 28.85ms
* geshi min: 46.00ms avg: 49.96ms max: 54.29ms
KeyLighter was about 2.28x faster than geshi
medium:
* KeyLighter min: 44.48ms avg: 48.01ms max: 51.19ms
* geshi min: 115.28ms avg: 118.77ms max: 121.21ms
KeyLighter was about 2.47x faster than geshi
large:
* KeyLighter min: 107.91ms avg: 111.36ms max: 115.06ms
* geshi min: 268.09ms avg: 275.53ms max: 283.67ms
KeyLighter was about 2.47x faster than geshi
very large:
* KeyLighter min: 643.25ms avg: 702.03ms max: 726.93ms
* geshi min: 1,428.25ms avg: 1,440.51ms max: 1,453.55ms
KeyLighter was about 2.05x faster than geshi