You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if re.fullmatch('\*?US[0-9]+[AB]', w.label) \
or re.fullmatch('\*?US[0-9]+[AB][/_(].*', w.label) \
or re.fullmatch('\*?US[0-9]+[AB][A-Z][a-z]{2}', w.label) \
or re.fullmatch('\*?US[0-9]+[AB][A-Z][a-z]{2}[/_(].*', w.label):
datacheckerrors.append(DatacheckEntry(r,[w.label],'US_LETTER'))
is nice and clean and readable and we can tell what's going on relatively easily. But it spends a lot of time rechecking long strings at the beginning of the label that we already know are the same.
m = re.search('^\*?US[0-9]+[AB]', w.label)
if m:
c = m.end(0)
if c == len(w.label) or w.label[c] in '/_(':
datacheckerrors.append(DatacheckEntry(r,[w.label],'US_LETTER'))
else:
# is it followed by a city abbrev?
m = re.search('^[A-Z][a-z]{2}', w.label[c:])
if m:
c += m.end(0)
if c == len(w.label) or w.label[c] in '/_(':
datacheckerrors.append(DatacheckEntry(r,[w.label],'US_LETTER'))
runs over 3 times as fast.
On a side note, I really miss the null terminator that C and C++ use; it comes in handy. I'd have preferred to not use the 2nd re.search, but I wanted to avoid a bunch of checking whether array indices overrun the string length. Yes, sometimes I will sacrifice a bit of speed in favor of some brevity of code. :) Edit: More experimentation... Looks like we can get away with it in this case, because of the checks for c == len(w.label). Invalid indices when slicing will just produce an empty string. Huzzah!
Putting way more time & effort into this than is sane.
box
v.8
v.8A
comments
noreaster
320 334
312 329
Only ran 200 passes. Results multiplied by 10.
lab1
191.3 198.1
197.9 195.5
lab1.5
161.9 158.6
158.0 161.3
lab2
231.5 240.4
226.7 238.5
lab3
341.7 339.9
334.1 336.2
Python 2
BiggaTomato
317.2 307.2
320.9 315.2
epoch
394.4 419.3
423 434.1
I don't need to worry about checking my array indices manually if I enclose the whole thing within try:/except IndexError: Dropping regexes altogether in favor of a more C-like approach that examines the individual characters runs 3-4x as fast depending on what machine.
try:
c = 3 if w.label[0] == '*' else 2
if w.label[c-2] == 'U' and w.label[c-1] == 'S' and w.label[c].isdigit():
while w.label[c].isdigit():
c += 1
if w.label[c] in 'AB':
c += 1
if c == len(w.label) or w.label[c] in '/_(':
datacheckerrors.append(DatacheckEntry(r,[w.label],'US_LETTER'))
# is it followed by a city abbrev?
elif w.label[c].isupper() and w.label[c+1].islower() and w.label[c+2].islower() \
and (c+3 == len(w.label) or w.label[c+3] in '/_('):
datacheckerrors.append(DatacheckEntry(r,[w.label],'US_LETTER'))
except IndexError:
pass
How much time will this actually save per update? About 0.3s! 🤣
Activity
yakra commentedon Nov 16, 2020
is nice and clean and readable and we can tell what's going on relatively easily. But it spends a lot of time rechecking long strings at the beginning of the label that we already know are the same.
runs over 3 times as fast.
On a side note, I really miss the null terminator that C and C++ use; it comes in handy. I'd have preferred to not use the 2nd
re.search, but I wanted to avoid a bunch of checking whether array indices overrun the string length. Yes, sometimes I will sacrifice a bit of speed in favor of some brevity of code. :)Edit: More experimentation... Looks like we can get away with it in this case, because of the checks for
c == len(w.label). Invalid indices when slicing will just produce an empty string. Huzzah!yakra commentedon Nov 17, 2020
Putting way more time & effort into this than is sane.
334
329
198.1
195.5
158.6
161.3
240.4
238.5
339.9
336.2
307.2
315.2
419.3
434.1
I don't need to worry about checking my array indices manually if I enclose the whole thing within
try:/except IndexError:Dropping regexes altogether in favor of a more C-like approach that examines the individual characters runs 3-4x as fast depending on what machine.How much time will this actually save per update? About 0.3s! 🤣