Last active
August 6, 2020 17:46
-
-
Save cmccandless/63a3560c42fa54014a67921d1db9fea3 to your computer and use it in GitHub Desktop.
Python regex compiled vs inline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from pathlib import Path | |
p = Path("big.txt") | |
t = p.read_text() | |
rgx = re.compile(r"\w+") | |
for _ in range(10): | |
rgx.findall(t) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from pathlib import Path | |
p = Path("big.txt") | |
t = p.read_text() | |
rgx = re.compile(r"\w+") | |
for _ in range(10): | |
rgx.findall(t) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from pathlib import Path | |
p = Path("big.txt") | |
t = p.read_text() | |
for _ in range(10): | |
re.findall(r'\w+', t) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# big.txt from https://norvig.com/big.txt | |
time python3.8 compiled.py | |
# real 0m2.292s | |
# user 0m2.091s | |
# sys 0m0.200s | |
time python3.8 literal.py | |
# | |
# real 0m2.287s | |
# user 0m2.030s | |
# sys 0m0.257s | |
time python3.8 compiled_in_loop.py | |
# | |
# real 0m2.286s | |
# user 0m2.025s | |
# sys 0m0.260s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment