Speeding up application startup
Mark Rowe
mark21rowe at yahoo.com
Fri May 11 22:52:55 EDT 2001
Hey,
Thanks for the info. Here is the relevant code. It is definately the
compiling of the expressions, because if i remove the compilation, it takes
less than one second to load the expressions. Also, the reason why i
compile all of the expressions at startup is that all my application does is
check to see if any given string is either blocked or allowed, due to the
expressions that it matches. So far, the only thing that i can do is sift
through the expression file by hand, and alter the expressions to be
slightly more general, therefore removing probably about 1/4 of them. I
shall do this when i get time
Mark
def ReadBlockFiles(files={ 'match_deny':'matchd.dat', 'reg_deny':'regd.dat',
'match_allow':'matcha.dat',
'reg_allow':'rega.dat' }):
global reg_deny_patterns, match_deny_patterns, \
reg_allow_patterns, match_allow_patterns
start = time.time()
try:
f = open(files['match_deny'], 'r')
match_deny_patterns = map(lambda x: x.strip(), f.readlines())
f.close()
except IOError:
pass
try:
f = open(files['reg_deny'], 'r')
for line in f.readlines():
line = line.strip()
if not reg_deny_patterns.has_key(line):
reg_deny_patterns[line] = re.compile(line)
f.close()
except IOError:
pass
try:
f = open(files['match_allow'], 'r')
match_allow_patterns = map(lambda x: x.strip(), f.readlines())
f.close()
except IOError:
pass
try:
f = open(files['reg_allow'], 'r')
for line in f.readlines():
line = line.strip()
if not reg_allow_patterns.has_key(line):
reg_allow_patterns[line] = re.compile(line)
f.close()
except IOError:
pass
end = time.time()
print "Loaded in %3.2f secs" % (end - start)
More information about the Python-list
mailing list