Skip to content
Yohan Boniface edited this page Sep 21, 2017 · 1 revision

Benchmark

wheezy.routing

from timeit import timeit
from wheezy.routing import PathRouter
paths = ['/user/', '/user/{id}', '/user/{id}/subpath', '/user/{id}/subpath', '/boat/', '/boat/{id}', '/boat/{id}/subpath', '/boat/{id}/subpath', '/horse/', '/horse/{id}', '/horse/{id}/subpath', '/horse/{id}/subpath', '/bicycle/', '/bicycle/{id}', '/bicycle/{id}/subpath', '/bicycle/{id}/subpath']
router = PathRouter()
for path in paths: router.add_route(path, {}) 
# First route
timeit("router.match('/user/')", number=100000, globals=globals())
> 0.02442249599698698
# Route in the middle, with placeholder
timeit("router.match('/horse/22/subpath')", number=100000, globals=globals())
> 0.4550689890020294
# Unknown route
timeit("router.match('/plane/22/subpath')", number=100000, globals=globals())
> 0.4855331080034375

kua

from timeit import timeit
from kua.routes import Routes
paths = ['/user/', '/user/:id', '/user/:id/subpath', '/user/:id/subpath', '/boat/', '/boat/:id', '/boat/:id/subpath', '/boat/:id/subpath', '/horse/', '/horse/:id', '/horse/:id/subpath', '/horse/:id/subpath', '/bicycle/', '/bicycle/:id', '/bicycle/:id/subpath', '/bicycle/:id/subpath']
routes = Routes()
for path in paths: routes.add(path, {})
# First flat route
timeit("routes.match('/user/')", number=100000, globals=globals())
> 0.4850989800033858
# Middle route with placeholder
timeit("routes.match('/horse/22/subpath')", number=100000, globals=globals())
> 0.5856593859934947
# Unknown route
> timeit("try:\n routes.match('/plane/')\nexcept:\n pass", number=100000, globals=globals())
> 0.2418586480052909

routes

from timeit import timeit
from routes import Mapper
paths = ['/user/', '/user/{id}', '/user/{id}/subpath', '/user/{id}/subpath', '/boat/', '/boat/{id}', '/boat/{id}/subpath', '/boat/{id}/subpath', '/horse/', '/horse/{id}', '/horse/{id}/subpath', '/horse/{id}/subpath', '/bicycle/', '/bicycle/{id}', '/bicycle/{id}/subpath', '/bicycle/{id}/subpath']
map = Mapper()
for path in paths: map.connect(path)
# First flat route
timeit("map.match('/user/')", number=100000, globals=globals())
> 0.6877457400041749
# Middle route with placeholder
timeit("map.match('/horse/22/subpath')", number=100000, globals=globals())
> 1.5864228989958065
# Unknown route
timeit("map.match('/plane/')", number=100000, globals=globals())
> 0.47646303399960743

falcon (with cython)

from timeit import timeit
from falcon.routing import CompiledRouter
router = CompiledRouter()
paths = ['/user/', '/user/{id}', '/user/{id}/subpath', '/user/{id}/subpath', '/boat/', '/boat/{id}', '/boat/{id}/subpath', '/boat/{id}/subpath', '/horse/', '/horse/{id}', '/horse/{id}/subpath', '/horse/{id}/subpath', '/bicycle/', '/bicycle/{id}', '/bicycle/{id}/subpath', '/bicycle/{id}/subpath']
for path in paths: router.add_route(path, {}, lambda x:x)
# First flat route
timeit("router.find('/user/')", number=100000, globals=globals())
> 0.1403805209993152
# Middle route with placeholder
timeit("router.find('/horse/22/subpath')", number=100000, globals=globals())
> 0.16354741399845807
# Unknown route
timeit("router.find('/plane/')", number=100000, globals=globals())
> 0.10904673599725356

Autoroutes

See https://github.com/pyrates/autoroutes/blob/master/tools/profile_.py

# First flat path:
> 0.018643455987330526
# Middle path with placeholder:
> 0.04477122200478334
# Not found path:
> 0.01965468199341558
Clone this wiki locally