Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@stakach
Copy link

@stakach stakach commented Nov 4, 2018

Comparing luislavena/radix with a hash for static route lookup.

Radix tree with a mix of static and route params paths
image
A radix tree with only static routes was 2.3 times slower than the hash.

I also removed the call to .upcase when parsing the request as the HTTP standard specifies that this should be case sensitive - as such all browsers will make the request in the required case already.

@tbrand
Copy link
Owner

tbrand commented Nov 4, 2018

That's amazing improvement! Thanks! πŸ‘

@tbrand tbrand merged commit ac3ca87 into tbrand:master Nov 4, 2018
@tbrand
Copy link
Owner

tbrand commented Nov 4, 2018

Your PR is shipped on https://github.com/tbrand/router.cr/releases/tag/v0.2.6 πŸŽ‰

@stakach
Copy link
Author

stakach commented Nov 4, 2018

When compiled with the --release flag the difference is even greater

image

The code I used to benchmark:

    tree = Radix::Tree(String).new

    path = "/GET/path/"
    hash = {
        "/GET/path/" => "woot!",
        "/GET/path/:id" => "other!",
        "/POST/path/:id" => "other2!"
    }
    tree.add("/GET/path/", "woot!")
    tree.add("/GET/path/:id", "other!")
    tree.add("/POST/path/:id", "other2!")

    Benchmark.ips do |x|
      x.report("Radix Lookup") do
          result = tree.find(path)
          raise "error" unless result.payload == "woot!"
     end
      x.report("Hash Lookup") do
          result = hash[path]
          raise "error" unless result == "woot!"
      end
    end

@tbrand
Copy link
Owner

tbrand commented Nov 4, 2018

Amazing! πŸŽ‰

waghanza pushed a commit to the-benchmarker/web-frameworks that referenced this pull request Nov 4, 2018
* update router.cr for improved performance

See: tbrand/router.cr#29

* use crystal 0.27.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants