Giter Site home page Giter Site logo

tsantos84 / serializer-benchmark Goto Github PK

View Code? Open in Web Editor NEW
15.0 4.0 3.0 178 KB

A PHP benchmark application to compare PHP serializer libraries

PHP 98.74% Dockerfile 1.26%
php7 performance-analysis symfony-serializer jms-serializer tsantos-serializer blackfire simple-serializer serialization-library benchmark overhead

serializer-benchmark's Introduction

Serializer Benchmark Build Status

This project aims to compare the performance of some most used and few less known JSON serialization libraries for PHP.

Inspiration

This benchmark attempts to compare serialization libraries performance-wise. All of the libraries have their own features, support different formats, added magic and other stuff, but for the sake of simplicity it was decided to simplify sample data to fit all of them.

The core of benchmarking set was implemented by Tales Santos, the author of TSantos serializer.

Instalation

Clone this repository in your workspace

git clone https://github.com/tsantos84/serializers-benchmarking.git

Install the application's dependencies

Using system installed composer

composer install -a --no-dev

or using composer in docker container:

docker run --rm --interactive --tty -v $(pwd):/app composer install -a --no-dev

Execution

The benchmark application can be executed as is with PHP 7.1 and above.

php vendor/bin/phpbench run --warmup=1 --report=tsantos

If you don't have PHP of required version you may use suitable Docker PHP image (PHP 7.1-cli-alpine).

docker run --rm -it -v $(pwd):/opt -w /opt php:7.1-cli-alpine php vendor/bin/phpbench run --warmup=1 --report=tsantos --group=serialize

Application parameters

There're 2 available benchmark groups:

  • serialize - run serialization benchmark only
  • deserialize - run deserialization benchmark only
php vendor/bin/phpbench run --warmup=1 --report=tsantos --group=serialize

Vendors

It is possible to see all the serializer libraries available in this benchmark and its version:

php vendor/bin/phpbench vendors

Benchmark Tool

This project was written based on PHPBench. Please, refer to its documentation page for further reading about all its runner options.

Blackfire Integration

Blackfire is a excelent tool to profile PHP applications and helps you to discover some bottleneck points. This project allows you to run benchmarks and send the call-graph to Blackfire's server so you can see how each library works internally.

Installation

In order to start using Blackfire, you first need to sign up on Blackfire.io and then you'll have access to your credentials.

Agent

Creates a new docker container with the Blackfire's Agent:

docker run -d \
  --name="blackfire" \
  -e BLACKFIRE_SERVER_ID={YOUR_BLACKFIRE_SERVER_ID_HERE} \
  -e BLACKFIRE_SERVER_TOKEN={YOUR_BLACKFIRE_SERVER_TOKEN_HERE} \
  blackfire/blackfire

PHP Executable

Create a custom PHP image with Blackfire extension installed and enabled:

cd /path/to/serializer-benchmark
docker build -t benchmark -f Dockerfile.blackfire .

Running the application

Now you can run the application using the PHP image create on step before:

docker run \
  --rm \
  -it \
  -v $(pwd):/opt \
  -w /opt \
  -e BLACKFIRE_CLIENT_ID={YOUR_BLACKFIRE_CLIENT_ID_HERE} \
  -e BLACKFIRE_CLIENT_TOKEN={YOUR_BLACKFIRE_CLIENT_TOKEN_HERE} \
  --link blackfire:blackfire \
  benchmark php vendor/bin/phpbench run --warmup=1 --report=tsantos --group=serialize --executor=blackfire

Docker Compose

Instead of running each container manually, you can use docker-compose to run the benchmarks. To accomplish this you need to create a copy of the docker-compose.yaml.dist file:

cp docker-compose.yml.dist docker-compose.yml

and run one of the following commands:

# perform serialization benchmark
docker-compose run --rm bench_serialize

# perform deserialization benchmark
docker-compose run --rm bench_deserialize

# perform serialization benchmark with Blackfire enabled
docker-compose run --rm bench_serialize_blackfire \
    -e BLACKFIRE_SERVER_ID={YOUR_BLACKFIRE_SERVER_ID} \
    -e BLACKFIRE_SERVER_TOKEN={YOUR_BLACKFIRE_SERVER_TOKEN} \
    -e BLACKFIRE_CLIENT_ID={YOUR_BLACKFIRE_CLIENT_ID} \
    -e BLACKFIRE_CLIENT_TOKEN={YOU_BLACKFIRE_CLIENT_TOKEN}

# perform deserialization benchmark with Blackfire enabled
docker-compose run --rm bench_deserialize_blackfire \
    -e BLACKFIRE_SERVER_ID={YOUR_BLACKFIRE_SERVER_ID} \
    -e BLACKFIRE_SERVER_TOKEN={YOUR_BLACKFIRE_SERVER_TOKEN} \
    -e BLACKFIRE_CLIENT_ID={YOUR_BLACKFIRE_CLIENT_ID} \
    -e BLACKFIRE_CLIENT_TOKEN={YOU_BLACKFIRE_CLIENT_TOKEN}

As you have your own copy of the docker-compose.yml file, you can define those environment variables there and save time when run the benchmarks with Blackfire enabled.

Note

By running the benchmark with Blackfire enabled you'll realize that the mean time will increase substantially. This behavior is expected because the Blackfire needs to introspect in your code and hence affects the benchmark metrics.

Contribution

Want to see more libraries in this benchmark? You can easily add new benchmarks by implementing the BenchInterface interface or extending the AbstractBench class which has a lot of help methods. Please, take a look at some of existing bench classes and you'll see how you can write your own benchmark.

serializer-benchmark's People

Contributors

andrew-demb avatar eduard-sukharev avatar tsantos84 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

serializer-benchmark's Issues

Benchmark with opcache

I believe the results here are skewed because benchmarking is not taking advantage of opcaching. It would be nice if a server could be set up with opcache properly configured to see how these libraries will perform in production.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.