Skip to content

Instantly share code, notes, and snippets.

View rybakit's full-sized avatar

Eugene Leonovich rybakit

View GitHub Profile
@rybakit
rybakit / bench_range_vs_values.php
Created July 5, 2016 07:24
array_values vs array_keys + range + count
<?php
function range_keys($n, $data) {
for ($i = 0; $i < $n; ++$i) {
if ($data) {
$r = array_keys($data) !== range(0, count($data) - 1);
} else {
$r = [];
}
}
@rybakit
rybakit / bench_big_array.php
Last active June 24, 2016 10:07
msgpack pure vs pecl big array
<?php
// @see https://github.com/msgpack/msgpack-php/issues/90
ini_set('memory_limit', '32G');
require __DIR__.'/../vendor/autoload.php';
if (extension_loaded('xdebug')) {
echo "The benchmark must be run with xdebug extension disabled.\n";
empty_loop 0.076
unpack_i16 2.097 2.021
ord_i16 0.925 0.849
unpack_u16 2.051 1.975
ord_u16 0.740 0.664
------------------------
Total 5.889
php -v
PHP 7.0.5 (cli) (built: Apr 23 2016 10:48:01) ( NTS )
<?php
// Borrowed from https://gist.github.com/denji/7c3c9d4b449f2699ec73
require __DIR__.'/../vendor/autoload.php';
ini_set("display_errors", 1);
ini_set("display_startup_errors", 1);
ini_set("error_reporting", E_ALL);
@rybakit
rybakit / bench_json_vs_msgpack.php
Last active March 30, 2020 09:01
pure msgpack.php vs json extension
<?php
use App\MessagePack\PackedMap;
use App\MessagePack\PackedMapTransformer;
use MessagePack\BufferUnpacker;
use MessagePack\Packer;
use MessagePack\PackOptions;
require __DIR__.'/vendor/autoload.php';
@rybakit
rybakit / 0.1 sec duration
Last active January 4, 2016 13:36
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
@rybakit
rybakit / JsonListener.php
Last active December 23, 2015 08:49
Json listener for Buzz http client
<?php
use Buzz\Listener\ListenerInterface;
use Buzz\Message\MessageInterface;
use Buzz\Message\RequestInterface;
class JsonListener implements ListenerInterface
{
/**
* {@inheritdoc}
@rybakit
rybakit / array_add.php
Last active December 12, 2015 07:38
array_replace() vs array union benchmark
<?php
for ($i = 0; $i < 1000000; ++$i) {
$server = $_SERVER;
$server += array(
'SERVER_NAME' => 'localhost',
'SERVER_PORT' => 80,
'HTTP_HOST' => 'localhost',
'HTTP_USER_AGENT' => 'Symfony/2.X',
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
@rybakit
rybakit / Chain.php
Last active February 1, 2023 14:35
Nested chain validator for symfony > 2.1
<?php
namespace Acme\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\Valid;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
/**
* @Annotation
@rybakit
rybakit / AcmeExtension.php
Last active December 10, 2015 20:58
RybakitNavigationBundle full example
<?php
// Twig/AcmeExtension.php
namespace Acme\DemoBundle\Twig\Extension;
use Symfony\Component\DependencyInjection\ContainerInterface;
class AcmeExtension extends \Twig_Extension
{
private $container;