/uri-parser-benchmarks

scripts to test and benchmark uri parsers

Primary LanguagePHPMIT LicenseMIT

URI parser benchmark

Build Status

Motivation

While developing League URL version 4, the need for replacing PHP parse_url function with a userland version which is more RFC3986 compliant was obvious.

This package sole purpose is to:

  • compare different PHP userland parser against any submitted URI.
  • test the resulting code overhead (speed + memory usage) vs PHP's parse_url function.

This is a work in progress. Feel free to update or improve the tests. It will help everyone get better compliant RFC3986 URI parser.

Of note: we are only testing URI parsing capabilities NOT URI validation which is a whole different topic.

Tested implementations

This package run the tests against the following implementations (order alphabetically):

And of course

All URI Parser packages are managed by composer. The tests are runned with the latest stable version

See the latest benchmark on Travis-CI

System Requirements

You need:

  • PHP >= 5.5.0 or HHVM >= 3.6, but the latest stable version of PHP/HHVM is recommended
  • the mbstring extension
  • the intl extension

Install

Clone this repo on a composer installed box and run the following command from the project root folder.

$ composer install

Scripts

There's two scripts in the package bin directory:

Parsing capabilities

The parser script returns the results from parsing a given URI with one of the available parser.

In the root directory run the following command:

$ php bin/parser --parser=league --uri="scheme://host:/path?#fragment"

By default if no URI is provided, the following URI will be used:

$uri = 'ftp://cnn.example.com&story=breaking_news:pass@10.0.0.1/top_story.htm?q=v&q=b#~toto';

The above command will output the result from parsing the given URI with the League\Uri\UriParser class.

You can of course change the parser by providing the parser "nickname".

  • native : parse_url
  • league : League\Uri\UriParser
  • pear : Net_URL2
  • zend : Zend\Uri\Uri
  • riimu : Riimu\Kit\UrlParser\UriParser

For more options you can issue the following command to display the script help message:

$ php bin/parser --help

Overhead capabilities

The benchmark script runs the benchmark against one implementation with a given URI.

$ php bin/benchmark --parser=zend --uri="scheme://host:/path?#fragment"

The above benchmark will use the Zend\Uri\Uri parsing capabilities and the submitted URI will be parsed 100 times with 3 iterations.

For more options you can issue the following command to display the script help message:

$ php bin/benchmark --help

Contributing

Contributions are welcome and will be fully credited. Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.