Bimba.git

ref: b3ed2a4684de4853eb1b744d88ff684c454c9067

converter/server/vendor/rybakit/msgpack/tests/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
<?php

/*
 * This file is part of the rybakit/msgpack.php package.
 *
 * (c) Eugene Leonovich <gen.work@gmail.com>
 *
 * 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\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(function ($code, $message) { throw new \RuntimeException($message); });

$targetAliases = getenv('MP_BENCH_TARGETS') ?: 'pure_p,pure_bu';
$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);

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_ps' => function () { return new PackerTarget('Packer (force_str)', new Packer(PackOptions::FORCE_STR)); },
    'pure_pa' => function () { return new PackerTarget('Packer (force_arr)', new Packer(PackOptions::FORCE_ARR)); },
    'pure_psa' => function () { return new PackerTarget('Packer (force_str|force_arr)', new Packer(PackOptions::FORCE_STR | PackOptions::FORCE_ARR)); },
    'pure_bu' => 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);