Closed as not planned
Description
Feature or enhancement
Proposal:
I had a test that I put my script in following.
import re
import time
rng = 1000000
# COMPILING IT BEFORE HAND
start = time.time()
pre_comp_pat = re.compile(r'[a-zA-Z]+')
for _ in range(rng):
pre_comp_pat.match("gaz")
end = time.time()
print("Time (pre-compiled) ", end - start)
# COMPILING IT INSIDE THE FOR LOOP
start = time.time()
for _ in range(rng):
pat = re.compile(r'[a-zA-Z]+')
pat.match("gaz")
end = time.time()
print("Time (compiling each it)", end - start)
# NEVER EXPLICITLY COMPILING IT
non_comp_pat = r'[a-zA-Z]+'
start = time.time()
for _ in range(rng):
re.match(non_comp_pat, "gaz")
end = time.time()
print("Time (not compiling)", end - start)
and the result is:
Time (pre-compiled) 0.19112229347229004
Time (compiling each it) 0.5717971324920654
Time (not compiling) 0.5644176006317139
I jumped to implementation
Lines 339 to 341 in 456e274
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response