-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
bench.php
99 lines (79 loc) · 3.28 KB
/
bench.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* This file is part of the rybakit/msgpack.php package.
*
* (c) Eugene Leonovich <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MessagePack\Tests;
use MessagePack\Packer;
use MessagePack\PackOptions;
use MessagePack\Tests\Perf\Benchmark\AverageableBenchmark;
use MessagePack\Tests\Perf\Benchmark\DurationBenchmark;
use MessagePack\Tests\Perf\Benchmark\FilterableBenchmark;
use MessagePack\Tests\Perf\Benchmark\IterationBenchmark;
use MessagePack\Tests\Perf\Benchmark\PausableBenchmark;
use MessagePack\Tests\Perf\Filter\ListFilter;
use MessagePack\Tests\Perf\Filter\RegexFilter;
use MessagePack\Tests\Perf\Runner;
use MessagePack\Tests\Perf\Target\BufferUnpackerTarget;
use MessagePack\Tests\Perf\Target\PackerTarget;
use MessagePack\Tests\Perf\Target\PeclFunctionPackTarget;
use MessagePack\Tests\Perf\Target\PeclFunctionUnpackTarget;
require __DIR__.'/../vendor/autoload.php';
if (extension_loaded('xdebug')) {
echo "The benchmark must be run with xdebug extension disabled.\n";
exit(42);
}
function resolve_filter($testNames)
{
if ('/' === $testNames[0]) {
return new RegexFilter($testNames);
}
if ('@' !== $testNames[0] && '@' !== $testNames[1]) {
return new ListFilter(explode(',', $testNames));
}
$exclude = '-' === $testNames[0];
switch (ltrim($testNames, '-@')) {
case 'slow':
return $exclude
? ListFilter::fromBlacklist(DataProvider::getSlowTestNames())
: ListFilter::fromWhitelist(DataProvider::getSlowTestNames());
case 'pecl_comp':
return $exclude
? ListFilter::fromWhitelist(DataProvider::getPeclIncompatibleTestNames())
: ListFilter::fromBlacklist(DataProvider::getPeclIncompatibleTestNames());
}
throw new \UnexpectedValueException(sprintf('Unknown test group "%s".', $testNames));
}
set_error_handler(static function ($code, $message) { throw new \RuntimeException($message); });
$targetAliases = getenv('MP_BENCH_TARGETS') ?: 'pure_p,pure_u';
$rounds = getenv('MP_BENCH_ROUNDS') ?: 3;
$testNames = getenv('MP_BENCH_TESTS') ?: '-@slow';
$benchmark = getenv('MP_BENCH_DURATION')
? new DurationBenchmark(getenv('MP_BENCH_DURATION'))
: new IterationBenchmark(getenv('MP_BENCH_ITERATIONS') ?: 100000);
$benchmark = new PausableBenchmark($benchmark);
if ($rounds) {
$benchmark = new AverageableBenchmark($benchmark, $rounds);
}
if ($testNames) {
$filter = resolve_filter($testNames);
$benchmark = new FilterableBenchmark($benchmark, $filter);
}
$targetFactories = [
'pecl_p' => function () { return new PeclFunctionPackTarget(); },
'pecl_u' => function () { return new PeclFunctionUnpackTarget(); },
'pure_p' => function () { return new PackerTarget('Packer'); },
'pure_pdsb' => function () { return new PackerTarget('Packer (detect_str_bin)', new Packer(PackOptions::DETECT_STR_BIN)); },
'pure_u' => function () { return new BufferUnpackerTarget('BufferUnpacker'); },
];
$targets = [];
foreach (explode(',', $targetAliases) as $alias) {
$targets[] = $targetFactories[trim($alias)]();
}
$runner = new Runner(DataProvider::provideData());
gc_disable();
$runner->run($benchmark, $targets);