Skip to content

Instantly share code, notes, and snippets.

@rybakit
Last active January 4, 2016 13:36
Show Gist options
  • Save rybakit/dcb3885d33fc6fc674bd to your computer and use it in GitHub Desktop.
Save rybakit/dcb3885d33fc6fc674bd to your computer and use it in GitHub Desktop.
pure msgpack.php vs json_* (dataProvider version)
$ MP_BENCH_DURATION=.01 MP_BENCH_TARGETS=pure_p,pure_u,json_p,json_u php tests/bench_json.php
Filter: MessagePack\Tests\Perf\Filter\NameFilter
Rounds: 3
Duration: .01
==============================================================================================
Test/Target MessagePack\Packer MessagePack\BufferUnpacker json_encode json_decode
----------------------------------------------------------------------------------------------
nil ......................... 39820.0000 ................ 24967.0000 . 65322.3333 . 55244.3333
false ....................... 38231.0000 ................ 24824.6667 . 63387.6667 . 56517.0000
true ........................ 39498.0000 ................ 24414.3333 . 57734.6667 . 58101.0000
7-bit uint #1 ............... 32559.0000 ................ 27380.3333 . 60910.6667 . 47421.6667
7-bit uint #2 ............... 36829.6667 ................ 30219.0000 . 56805.3333 . 50282.6667
7-bit uint #3 ............... 31125.0000 ................ 28090.3333 . 61717.6667 . 47606.0000
5-bit sint #1 ............... 35976.3333 ................ 22931.6667 . 63524.0000 . 50433.0000
5-bit sint #2 ............... 34162.3333 ................ 24407.6667 . 64314.0000 . 40601.0000
5-bit sint #3 ............... 36074.3333 ................ 23773.6667 . 62607.3333 . 49450.0000
8-bit uint #1 ............... 27309.3333 ................ 12688.3333 . 57219.3333 . 40483.6667
8-bit uint #2 ............... 27555.3333 ................ 12568.6667 . 61919.3333 . 48981.6667
8-bit uint #3 ............... 27521.0000 ................ 11439.6667 . 62018.3333 . 37564.0000
16-bit uint #1 .............. 26259.3333 ................ 10917.6667 . 54446.3333 . 48681.3333
16-bit uint #2 .............. 26525.0000 ................. 9140.3333 . 53020.3333 . 47615.0000
16-bit uint #3 .............. 26027.6667 ................ 11684.3333 . 55365.3333 . 47581.6667
32-bit uint #1 .............. 26770.3333 ................ 11701.3333 . 60175.6667 . 46956.0000
32-bit uint #2 .............. 25075.0000 ................ 11640.6667 . 50133.3333 . 39793.3333
32-bit uint #3 .............. 26508.0000 ................ 10926.3333 . 57624.6667 . 43769.3333
64-bit uint #1 .............. 18589.3333 ................. 8943.0000 . 59064.0000 . 41840.3333
64-bit uint #2 .............. 20278.0000 ................ 10040.3333 . 54561.3333 . 37255.6667
8-bit int #1 ................ 27379.0000 ................ 11163.6667 . 57465.0000 . 45837.6667
8-bit int #2 ................ 25704.3333 ................ 12424.3333 . 59402.6667 . 47774.3333
8-bit int #3 ................ 26308.3333 ................ 11022.6667 . 61721.6667 . 49050.3333
16-bit int #1 ............... 25491.6667 ................ 10587.3333 . 61294.3333 . 45339.3333
16-bit int #2 ............... 25196.0000 ................. 9528.3333 . 42534.6667 . 45602.6667
16-bit int #3 ............... 24663.6667 ................ 10602.6667 . 60634.6667 . 47480.0000
32-bit int #1 ............... 25686.3333 ................ 10545.0000 . 59733.6667 . 46255.0000
32-bit int #2 ............... 24148.3333 ................ 10627.6667 . 53046.6667 . 40558.0000
32-bit int #3 ............... 23381.0000 ................ 10327.6667 . 59439.0000 . 43876.3333
64-bit int #1 ............... 20756.3333 ................. 9906.3333 . 57118.6667 . 43775.6667
64-bit int #2 ............... 18998.0000 ................. 8518.3333 . 47380.0000 . 33881.0000
64-bit int #3 ............... 20744.0000 ................. 8991.3333 . 55349.6667 . 37895.6667
64-bit float #1 ...................... I ......................... I .......... F .......... F
64-bit float #2 ............. 23933.6667 ................ 11146.0000 . 45864.6667 . 48685.6667
64-bit float #3 ............. 23256.0000 ................ 11220.3333 . 46493.3333 . 46151.6667
fix string #1 ............... 18681.3333 ................ 25071.0000 . 53138.6667 . 56270.3333
fix string #2 ............... 22726.0000 ................ 17067.3333 . 62077.0000 . 51923.3333
fix string #3 ............... 23049.3333 ................ 17803.6667 . 52013.0000 . 42846.0000
fix string #4 ............... 20774.6667 ................ 17858.3333 . 34030.6667 . 43491.6667
8-bit string #1 ............. 17811.6667 ................. 9049.6667 . 36129.6667 . 44167.6667
8-bit string #2 ............. 14587.3333 ................. 7434.0000 . 18326.6667 . 34221.3333
8-bit string #3 ............. 12952.6667 ................. 8923.0000 . 12992.3333 . 23774.3333
16-bit string #1 ............ 13468.6667 ................. 9040.0000 . 12995.3333 . 22805.3333
16-bit string #2 .............. 185.3333 ................. 2704.6667 .... 52.6667 ... 171.6667
32-bit string ................. 185.3333 ................. 2695.3333 .... 55.6667 ... 168.0000
wide char string #1 ......... 18102.0000 ................ 16843.0000 . 52171.6667 . 39604.0000
wide char string #2 ......... 16325.6667 ................. 9560.6667 . 23757.0000 . 21395.6667
8-bit binary #1 ...................... I ......................... I .......... F .......... F
8-bit binary #2 ...................... I ......................... I .......... F .......... F
8-bit binary #3 ...................... I ......................... I .......... F .......... F
16-bit binary ........................ I ......................... I .......... F .......... F
32-bit binary ........................ I ......................... I .......... F .......... F
fixext 1 ............................. I ......................... I .......... F .......... F
fixext 2 ............................. I ......................... I .......... F .......... F
fixext 4 ............................. I ......................... I .......... F .......... F
fixext 8 ............................. I ......................... I .......... F .......... F
fixext 16 ............................ I ......................... I .......... F .......... F
8-bit ext ............................ I ......................... I .......... F .......... F
16-bit ext ........................... I ......................... I .......... F .......... F
32-bit ext ........................... I ......................... I .......... F .......... F
fix array #1 ................ 24590.6667 ................ 21405.0000 . 62135.0000 . 37089.6667
fix array #2 ................. 7600.6667 ................. 6968.6667 . 45252.0000 . 25941.0000
16-bit array #1 .............. 2214.3333 ................. 2349.6667 . 23341.3333 .. 8339.6667
16-bit array #2 ...................... S ......................... S .......... S .......... S
32-bit array ......................... S ......................... S .......... S .......... S
complex array ........................ I ......................... I .......... F .......... F
fix map #1 ........................... I ......................... I .......... F .......... F
fix map #2 ........................... I ......................... I .......... F .......... F
fix map #3 ........................... I ......................... I .......... F .......... F
16-bit map #1 ........................ I ......................... I .......... F .......... F
16-bit map #2 ........................ S ......................... S .......... S .......... S
32-bit map ........................... S ......................... S .......... S .......... S
complex map .......................... I ......................... I .......... F .......... F
==============================================================================================
Total 1151596.3333 674085.0000 2437819.0000 2010551.6667
Skipped 4 4 4 4
Failed 0 0 20 20
Ignored 20 20 0 0
$ MP_BENCH_ITERATIONS=10000 MP_BENCH_TARGETS=pure_p,pure_u,json_p,json_u MP_BENCH_TESTS='16-bit string #2,32-bit string,16-bit array #2,32-bit array,-16-bit map #2,32-bit map' php tests/bench_json.php
Filter: MessagePack\Tests\Perf\Filter\NameFilter
Rounds: 3
Iterations: 10000
==============================================================================================
Test/Target MessagePack\Packer MessagePack\BufferUnpacker json_encode json_decode
----------------------------------------------------------------------------------------------
16-bit string #2 ................ 0.5492 .................... 0.0370 ..... 1.7849 ..... 0.6042
32-bit string ................... 0.5419 .................... 0.0358 ..... 1.7466 ..... 0.5927
...
16-bit array #2 ................ 16.0620 ................... 14.5757 ..... 0.9471 ..... 4.9321
32-bit array ................... 16.0873 ................... 14.8276 ..... 0.9435 ..... 4.9157
...
16-bit map #1 ........................ S ......................... S .......... S .......... S
16-bit map #2 ........................ I ......................... I .......... F .......... F
$ MP_BENCH_ITERATIONS=100000 MP_BENCH_TARGETS=pure_p,pure_u,json_p,json_u MP_BENCH_TESTS='-16-bit string #2,-32-bit string,-16-bit array #2,-32-bit array,-16-bit map #2,-32-bit map' php tests/bench_json.php
Filter: MessagePack\Tests\Perf\Filter\NameFilter
Rounds: 3
Iterations: 100000
==============================================================================================
Test/Target MessagePack\Packer MessagePack\BufferUnpacker json_encode json_decode
----------------------------------------------------------------------------------------------
nil ............................. 0.0161 .................... 0.0308 ..... 0.0065 ..... 0.0088
false ........................... 0.0161 .................... 0.0323 ..... 0.0059 ..... 0.0090
true ............................ 0.0175 .................... 0.0341 ..... 0.0092 ..... 0.0090
7-bit uint #1 ................... 0.0197 .................... 0.0290 ..... 0.0064 ..... 0.0117
7-bit uint #2 ................... 0.0183 .................... 0.0241 ..... 0.0072 ..... 0.0123
7-bit uint #3 ................... 0.0182 .................... 0.0260 ..... 0.0074 ..... 0.0125
5-bit sint #1 ................... 0.0207 .................... 0.0328 ..... 0.0056 ..... 0.0129
5-bit sint #2 ................... 0.0211 .................... 0.0304 ..... 0.0070 ..... 0.0123
5-bit sint #3 ................... 0.0188 .................... 0.0307 ..... 0.0073 ..... 0.0120
8-bit uint #1 ................... 0.0308 .................... 0.0725 ..... 0.0077 ..... 0.0131
8-bit uint #2 ................... 0.0291 .................... 0.0753 ..... 0.0078 ..... 0.0124
8-bit uint #3 ................... 0.0280 .................... 0.0702 ..... 0.0081 ..... 0.0113
16-bit uint #1 .................. 0.0306 .................... 0.0803 ..... 0.0075 ..... 0.0127
16-bit uint #2 .................. 0.0296 .................... 0.0788 ..... 0.0077 ..... 0.0130
16-bit uint #3 .................. 0.0299 .................... 0.0795 ..... 0.0080 ..... 0.0130
32-bit uint #1 .................. 0.0290 .................... 0.0817 ..... 0.0078 ..... 0.0130
32-bit uint #2 .................. 0.0299 .................... 0.0802 ..... 0.0092 ..... 0.0144
32-bit uint #3 .................. 0.0321 .................... 0.0817 ..... 0.0093 ..... 0.0151
64-bit uint #1 .................. 0.0447 .................... 0.0934 ..... 0.0103 ..... 0.0160
64-bit uint #2 .................. 0.0440 .................... 0.0929 ..... 0.0100 ..... 0.0191
8-bit int #1 .................... 0.0288 .................... 0.0748 ..... 0.0080 ..... 0.0126
8-bit int #2 .................... 0.0280 .................... 0.0736 ..... 0.0078 ..... 0.0128
8-bit int #3 .................... 0.0311 .................... 0.0751 ..... 0.0085 ..... 0.0124
16-bit int #1 ................... 0.0291 .................... 0.0898 ..... 0.0078 ..... 0.0127
16-bit int #2 ................... 0.0288 .................... 0.0883 ..... 0.0103 ..... 0.0129
16-bit int #3 ................... 0.0294 .................... 0.0885 ..... 0.0079 ..... 0.0133
32-bit int #1 ................... 0.0341 .................... 0.0925 ..... 0.0085 ..... 0.0137
32-bit int #2 ................... 0.0299 .................... 0.0944 ..... 0.0089 ..... 0.0144
32-bit int #3 ................... 0.0300 .................... 0.0994 ..... 0.0083 ..... 0.0150
64-bit int #1 ................... 0.0408 .................... 0.0949 ..... 0.0084 ..... 0.0149
64-bit int #2 ................... 0.0550 .................... 0.1050 ..... 0.0094 ..... 0.0166
64-bit int #3 ................... 0.0422 .................... 0.0961 ..... 0.0101 ..... 0.0198
64-bit float #1 ...................... I ......................... I .......... F .......... F
64-bit float #2 ................. 0.0373 .................... 0.0828 ..... 0.0145 ..... 0.0129
64-bit float #3 ................. 0.0354 .................... 0.0822 ..... 0.0114 ..... 0.0139
fix string #1 ................... 0.0382 .................... 0.0336 ..... 0.0058 ..... 0.0095
fix string #2 ................... 0.0352 .................... 0.0515 ..... 0.0098 ..... 0.0148
fix string #3 ................... 0.0430 .................... 0.0604 ..... 0.0081 ..... 0.0123
fix string #4 ................... 0.0431 .................... 0.0475 ..... 0.0187 ..... 0.0153
8-bit string #1 ................. 0.0493 .................... 0.0991 ..... 0.0166 ..... 0.0144
8-bit string #2 ................. 0.0560 .................... 0.1017 ..... 0.0314 ..... 0.0209
8-bit string #3 ................. 0.0665 .................... 0.1050 ..... 0.0719 ..... 0.0352
16-bit string #1 ................ 0.0680 .................... 0.1037 ..... 0.0787 ..... 0.0358
16-bit string #2 ..................... S ......................... S .......... S .......... S
32-bit string ........................ S ......................... S .......... S .......... S
wide char string #1 ............. 0.0408 .................... 0.0513 ..... 0.0110 ..... 0.0162
wide char string #2 ............. 0.0516 .................... 0.0966 ..... 0.0287 ..... 0.0411
8-bit binary #1 ...................... I ......................... I .......... F .......... F
8-bit binary #2 ...................... I ......................... I .......... F .......... F
8-bit binary #3 ...................... I ......................... I .......... F .......... F
<?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.
*/
use MessagePack\Tests\DataProvider;
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\NameFilter;
use MessagePack\Tests\Perf\Runner;
use MessagePack\Tests\Perf\Target\BufferUnpackerTarget;
use MessagePack\Tests\Perf\Target\JsonDecodeTarget;
use MessagePack\Tests\Perf\Target\JsonEncodeTarget;
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);
}
set_error_handler(function ($code, $message) { throw new \RuntimeException($message); });
$targetNames = getenv('MP_BENCH_TARGETS') ?: 'pure_p,pure_u';
$rounds = getenv('MP_BENCH_ROUNDS') ?: 3;
$testNames = getenv('MP_BENCH_TESTS') ?: '-16-bit array #2, -32-bit array, -16-bit map #2, -32-bit map';
$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) {
$benchmark = new FilterableBenchmark($benchmark, new NameFilter(explode(',', $testNames)));
}
$targetFactories = [
'pecl_p' => function () { return new PeclFunctionPackTarget(); },
'pecl_u' => function () { return new PeclFunctionUnpackTarget(); },
'pure_p' => function () { return new PackerTarget(); },
'pure_u' => function () { return new BufferUnpackerTarget(); },
'json_p' => function () { return new JsonEncodeTarget(); },
'json_u' => function () { return new JsonDecodeTarget(); },
];
$targets = [];
foreach (explode(',', $targetNames) as $targetName) {
$targets[] = $targetFactories[trim($targetName)]();
}
$runner = new Runner(DataProvider::provideData());
gc_disable();
$runner->run($benchmark, $targets);
<?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\Perf\Target;
use MessagePack\Tests\Perf\Test;
class JsonDecodeTarget implements Target
{
/**
* {@inheritdoc}
*/
public function getName()
{
return 'json_decode';
}
/**
* {@inheritdoc}
*/
public function sanitize(Test $test)
{
if ($test->getRaw() !== json_decode(json_encode($test->getRaw()))) {
var_dump($test->getRaw());
throw new \UnexpectedValueException('$raw !== json_decode(json_encode(($raw))');
}
$test->jsonPacked = json_encode($test->getRaw());
}
/**
* {@inheritdoc}
*/
public function perform(Test $test)
{
json_decode($test->jsonPacked);
}
/**
* {@inheritdoc}
*/
public function calibrate(Test $test)
{
$test->jsonPacked;
}
}
<?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\Perf\Target;
use MessagePack\Tests\Perf\Test;
class JsonEncodeTarget implements Target
{
/**
* {@inheritdoc}
*/
public function getName()
{
return 'json_encode';
}
/**
* {@inheritdoc}
*/
public function sanitize(Test $test)
{
if ($test->getRaw() !== json_decode(json_encode($test->getRaw()))) {
throw new \UnexpectedValueException('$raw !== json_decode(json_encode(($raw))');
}
}
/**
* {@inheritdoc}
*/
public function perform(Test $test)
{
json_encode($test->getRaw());
}
/**
* {@inheritdoc}
*/
public function calibrate(Test $test)
{
$test->getRaw();
}
}
PHP 7.0.1 (cli) (built: Dec 21 2015 22:03:35) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment