]> git.ipfire.org Git - thirdparty/tornado.git/commit
httputil: use compiled re patterns 2723/head
authorRan Benita <ran@unusedvar.com>
Tue, 6 Aug 2019 16:18:41 +0000 (19:18 +0300)
committerRan Benita <ran@unusedvar.com>
Tue, 6 Aug 2019 16:24:52 +0000 (19:24 +0300)
commit61a535b261117d85839621ac8de4473e9135b402
treec90cd7c236bf0b91899a5cc59e2803ce9935a007
parent549edaf64d08bedf0228489c062d1ff3f0281320
httputil: use compiled re patterns

This is slightly faster than using the builtin cache, e.g.:

With benchmark below (Python 3.7, Linux):

before: 0.7284867879934609
after:  0.2657967659761198

```py
import re
from time import perf_counter

line = 'HTTP/1.1'

_http_version_re = re.compile(r"^HTTP/1\.[0-9]$")

start = perf_counter()
for i in range(1000000):
    _http_version_re.match(line)
print(perf_counter() - start)

start = perf_counter()
for i in range(1000000):
    re.match(r"^HTTP/1\.[0-9]$", line)
print(perf_counter() - start)
```
tornado/httputil.py