Skip to content

Instantly share code, notes, and snippets.

@deronnax
Created March 26, 2015 09:53
Show Gist options
  • Save deronnax/984499ee7ef62b9b81f4 to your computer and use it in GitHub Desktop.
Save deronnax/984499ee7ef62b9b81f4 to your computer and use it in GitHub Desktop.
import re
import time
reg = re.compile(r'__version__\s*=\s*[\'"]([^\'"]*)[\'"]')
with open('requests/__init__.py', 'r') as fd:
t1 = time.time()
version = reg.search(fd.read()).group()
t2 = time.time()
print version
print 'mine:', (t2 - t1) * 1000
with open('requests/__init__.py', 'r') as fd:
t1 = time.time()
for line in fd:
m = reg.match(line)
if m:
version = m.group(1)
break
t2 = time.time()
print version
print 'his', (t2 - t1) * 1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment