darpi-rs / darpi

A rust web framework with safety and speed in mind.
https://darpi-rs.github.io/book/
33 stars 1 forks source link

gonzales is slow on my literals-only benchmark #23

Closed malaire closed 3 years ago

malaire commented 3 years ago

I added gonzales to my literals-only benchmark (i.e. no params) and it's much slower than matchit (or my work-in-progress matcher):

test literals-full/MatchIt/20    ... bench:         608 ns/iter (+/- 17)
test literals-full/Matcher/20    ... bench:         839 ns/iter (+/- 9)
test literals-full/gonzales/20   ... bench:        2378 ns/iter (+/- 30)

test literals-full/MatchIt/200   ... bench:        9089 ns/iter (+/- 67)
test literals-full/Matcher/200   ... bench:       18144 ns/iter (+/- 289)
test literals-full/gonzales/200  ... bench:       49354 ns/iter (+/- 1211)

test literals-full/MatchIt/2000  ... bench:      210733 ns/iter (+/- 1754)
test literals-full/Matcher/2000  ... bench:      346750 ns/iter (+/- 5215)
test literals-full/gonzales/2000 ... bench:      608682 ns/iter (+/- 16586)

Each iteration makes 20/200/2000 matches against 18/180/1800 routes, full code is here.

ps. I'm mentioning this because README says that "gonzales is the fastest http router in the business" but that is not the case here.

petar-dambovaliev commented 3 years ago

Interesting. I have tailored the code to be fast for the most common case, which is having routes with parameters and multisegments. The last time i ran the benchmarks in the crate, i added them to the README file. On linux and windows, its 50/50 between gonzales and matchit. On mac, i win hands down. I could further optimize for this specific case but i don't think its important. To me, the average performance is what matters.

malaire commented 3 years ago

ok, this is probably rarer use case for a router. Data in the test is actual data from URLs, but normally you'd match it as parameter and then e.g. fetch corresponding ID from database. I'm interested in knowing how well a router can match this directly.