Skip to content

Instantly share code, notes, and snippets.

@azjezz
Last active June 5, 2021 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azjezz/b2d09a6104b0bdfa4e00f3df96aadf7a to your computer and use it in GitHub Desktop.
Save azjezz/b2d09a6104b0bdfa4e00f3df96aadf7a to your computer and use it in GitHub Desktop.

uncached

This benchmark runs with cache disabled for all of Symfony, Fastroute, and HackRouting.

The (matcher/dispatcher/resolver) is being created in each iteration from scratch.

Ranking:

  1. FastRoute
  2. Symfony
  3. HackRouting
❯ php -dopcache.jit=1235 -dopcache.enable_cli=yes -dopcache.enable=yes -dapc.enable=1 -dapc.enable_cli=1 scripts/quick-benchmark.php
 18/18 [============================] 100%
+------------------+--------------+--------+------------------+-----------------+
| Case             | Scenario     | Routes | Time             | Per Second      |
+------------------+--------------+--------+------------------+-----------------+
| fast_mark        | benchAll     | 364    | 0.358438 seconds | 1015.5172855092 |
| fast_group_pos   | benchAll     | 364    | 0.364594 seconds | 998.37018504217 |
| fast_group_count | benchLast    | 300    | 0.303401 seconds | 988.79043436988 |
| fast_group_count | benchAll     | 364    | 0.386376 seconds | 942.08773412943 |
| fast_group_pos   | benchLast    | 300    | 0.318806 seconds | 941.01064187799 |
| fast_mark        | benchLast    | 300    | 0.320328 seconds | 936.54005461638 |
| fast_char_count  | benchLast    | 300    | 0.332997 seconds | 900.90943588055 |
| fast_char_count  | benchAll     | 364    | 0.416937 seconds | 873.03333960443 |
| fast_group_count | benchLongest | 300    | 0.373555 seconds | 803.09470941783 |
| fast_group_pos   | benchLongest | 300    | 0.388049 seconds | 773.09799237648 |
| fast_char_count  | benchLongest | 300    | 0.391293 seconds | 766.6888049125  |
| fast_mark        | benchLongest | 300    | 0.401180 seconds | 747.79395377943 |
| symfony          | benchAll     | 364    | 0.548740 seconds | 663.33793712325 |
| symfony          | benchLongest | 300    | 0.496965 seconds | 603.66432517024 |
| symfony          | benchLast    | 300    | 0.798387 seconds | 375.75759747578 |
| hack_routing     | benchLast    | 300    | 2.875024 seconds | 104.34695210314 |
| hack_routing     | benchAll     | 364    | 3.538484 seconds | 102.86891634842 |
| hack_routing     | benchLongest | 300    | 2.965042 seconds | 101.17900945837 |
+------------------+--------------+--------+------------------+-----------------+

cached.

This benchmark runs with cache enabled for all of Symfony, Fastroute, and HackRouting, and it reflects real-world scenarios when runnig your application using traditional setup ( fpm/fastcgi ).

The (matcher/dispatcher/resolver) is being created in each iteration from cache.

Ranking:

  1. FastRoute
  2. HackRouting
  3. HackRouting ( APCU )
  4. Symfony
❯ php -dopcache.jit=1235 -dopcache.enable_cli=yes -dopcache.enable=yes -dapc.enable=1 -dapc.enable_cli=1 scripts/quick-benchmark.php
 21/21 [============================] 100%
+--------------------------+--------------+--------+------------------+-----------------+
| Case                     | Scenario     | Routes | Time             | Per Second      |
+--------------------------+--------------+--------+------------------+-----------------+
| fast_mark_cached         | benchAll     | 364    | 0.005237 seconds | 69507.245891191 |
| fast_mark_cached         | benchLast    | 300    | 0.005077 seconds | 59091.349675965 |
| fast_group_pos_cached    | benchAll     | 364    | 0.006182 seconds | 58878.775780949 |
| fast_group_count_cached  | benchLast    | 300    | 0.005186 seconds | 57847.149687385 |
| fast_char_count_cached   | benchAll     | 364    | 0.006810 seconds | 53451.201064314 |
| fast_group_count_cached  | benchAll     | 364    | 0.006956 seconds | 52329.962502142 |
| fast_char_count_cached   | benchLast    | 300    | 0.005876 seconds | 51056.652465003 |
| fast_group_pos_cached    | benchLast    | 300    | 0.006171 seconds | 48614.580999112 |
| hack_routing_cached      | benchLast    | 300    | 0.047256 seconds | 6348.4011583908 |
| hack_routing_apcu_cached | benchLast    | 300    | 0.050613 seconds | 5927.3116111679 |
| hack_routing_apcu_cached | benchAll     | 364    | 0.064140 seconds | 5675.0996424084 |
| fast_mark_cached         | benchLongest | 300    | 0.053888 seconds | 5567.0936143667 |
| fast_group_count_cached  | benchLongest | 300    | 0.054326 seconds | 5522.2361197056 |
| fast_char_count_cached   | benchLongest | 300    | 0.057659 seconds | 5202.9904068806 |
| hack_routing_cached      | benchAll     | 364    | 0.070963 seconds | 5129.4404515522 |
| fast_group_pos_cached    | benchLongest | 300    | 0.059489 seconds | 5042.9481193516 |
| hack_routing_apcu_cached | benchLongest | 300    | 0.112070 seconds | 2676.8963697943 |
| hack_routing_cached      | benchLongest | 300    | 0.128935 seconds | 2326.7520104735 |
| symfony_compiled         | benchLast    | 300    | 0.333336 seconds | 899.99248987744 |
| symfony_compiled         | benchAll     | 364    | 0.406595 seconds | 895.23975318154 |
| symfony_compiled         | benchLongest | 300    | 0.398749 seconds | 752.3532204387  |
+--------------------------+--------------+--------+------------------+-----------------+

instance.

This benchmark runs with cache enabled for all of Symfony, Fastroute, and HackRouting, and it reflects real-world scenarios when runnig your application using a long running process server such as Amphp, ReactPHP, Roadrunner...

The (matcher/dispatcher/resolver) is created once and used in each iteration.

Ranking:

  1. Symfony
  2. FastRoute/HackRouting ( tie after multiple runs )
❯ php -dopcache.jit=1235 -dopcache.enable_cli=yes -dopcache.enable=yes -dapc.enable=1 -dapc.enable_cli=1 scripts/quick-benchmark.php
 18/18 [============================] 100%
+---------------------------+--------------+--------+------------------+-----------------+
| Case                      | Scenario     | Routes | Time             | Per Second      |
+---------------------------+--------------+--------+------------------+-----------------+
| symfony_instance          | benchAll     | 364    | 0.001703 seconds | 213737.45709085 |
| symfony_instance          | benchLast    | 300    | 0.001650 seconds | 181807.71564803 |
| fast_mark_instance        | benchLast    | 300    | 0.002801 seconds | 107097.72746617 |
| fast_char_count_instance  | benchAll     | 364    | 0.003597 seconds | 101194.84695433 |
| fast_group_pos_instance   | benchAll     | 364    | 0.004016 seconds | 90639.198290193 |
| fast_mark_instance        | benchAll     | 364    | 0.004131 seconds | 88112.578980781 |
| hack_routing_instance     | benchLast    | 300    | 0.003573 seconds | 83964.44681703  |
| fast_char_count_instance  | benchLast    | 300    | 0.003735 seconds | 80325.004787743 |
| fast_group_count_instance | benchLast    | 300    | 0.003739 seconds | 80237.928835608 |
| fast_group_count_instance | benchAll     | 364    | 0.004670 seconds | 77945.915964671 |
| fast_group_pos_instance   | benchLast    | 300    | 0.004213 seconds | 71206.564427593 |
| hack_routing_instance     | benchAll     | 364    | 0.007911 seconds | 46012.07486212  |
| fast_group_count_instance | benchLongest | 300    | 0.055415 seconds | 5413.6816562548 |
| fast_char_count_instance  | benchLongest | 300    | 0.057208 seconds | 5244.0162035107 |
| fast_mark_instance        | benchLongest | 300    | 0.058230 seconds | 5151.9692099822 |
| fast_group_pos_instance   | benchLongest | 300    | 0.058932 seconds | 5090.6072117777 |
| symfony_instance          | benchLongest | 300    | 0.060087 seconds | 4992.7435482335 |
| hack_routing_instance     | benchLongest | 300    | 0.069444 seconds | 4320.0164795551 |
+---------------------------+--------------+--------+------------------+-----------------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment