- Results that take less than 0.1 seconds are not cached anymore. I
wonder if any protocols are that fast :)
This commit is contained in:
parent
533cf46080
commit
76ad1ec696
@ -12,15 +12,25 @@
|
|||||||
# - Maybe it is an idea to time the output. If Scyther takes less
|
# - Maybe it is an idea to time the output. If Scyther takes less
|
||||||
# than a second, we don't need to cache the output. That would
|
# than a second, we don't need to cache the output. That would
|
||||||
# reduce the required cache size significantly.
|
# reduce the required cache size significantly.
|
||||||
|
# If so, we only need to create directories for the cached files
|
||||||
|
# we actually create.
|
||||||
#
|
#
|
||||||
|
|
||||||
import md5
|
import md5
|
||||||
import commands
|
import commands
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
from tempfile import NamedTemporaryFile, gettempdir
|
from tempfile import NamedTemporaryFile, gettempdir
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Global definitions
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Minimum duration for something to get into the cache
|
||||||
|
CacheTimer = 0.1
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# How to call Scyther
|
# How to call Scyther
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
@ -75,7 +85,7 @@ def evaluate (argumentstring, inputstring):
|
|||||||
# Determine name
|
# Determine name
|
||||||
def cachefilename(id):
|
def cachefilename(id):
|
||||||
fn = gettempdir() + "/scyther/"
|
fn = gettempdir() + "/scyther/"
|
||||||
fn = fn + slashcutter(id,"/",2,4)
|
fn = fn + slashcutter(id,"/",3,2)
|
||||||
fn = fn + ".txt"
|
fn = fn + ".txt"
|
||||||
return fn
|
return fn
|
||||||
|
|
||||||
@ -93,7 +103,6 @@ def evaluate (argumentstring, inputstring):
|
|||||||
|
|
||||||
# Determine the unique filename for this test
|
# Determine the unique filename for this test
|
||||||
cachefile = cachefilename(cacheid())
|
cachefile = cachefilename(cacheid())
|
||||||
ensureDirectories(cachefile)
|
|
||||||
|
|
||||||
# Does it already exist?
|
# Does it already exist?
|
||||||
if os.path.exists(cachefile):
|
if os.path.exists(cachefile):
|
||||||
@ -101,19 +110,27 @@ def evaluate (argumentstring, inputstring):
|
|||||||
f = open(cachefile,'r')
|
f = open(cachefile,'r')
|
||||||
res = f.read()
|
res = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
|
# TODO technically, we should store the status in the
|
||||||
|
# cache file as well. For now, we just return 0 status.
|
||||||
return (0,res)
|
return (0,res)
|
||||||
else:
|
else:
|
||||||
# Hmm, we need to compute this result
|
# Hmm, we need to compute this result
|
||||||
|
# Compute duration (in seconds)
|
||||||
h = NamedTemporaryFile()
|
h = NamedTemporaryFile()
|
||||||
h.write(inputstring)
|
h.write(inputstring)
|
||||||
h.flush()
|
h.flush()
|
||||||
|
starttime = time.time()
|
||||||
(status, scout) = scythercall (argumentstring, h.name)
|
(status, scout) = scythercall (argumentstring, h.name)
|
||||||
|
duration = time.time() - starttime
|
||||||
h.close()
|
h.close()
|
||||||
|
|
||||||
# Write cache file even if it's wrong
|
# Only cache if it took some time
|
||||||
f = open(cachefile,'w')
|
if duration >= CacheTimer:
|
||||||
f.write(scout)
|
# Write cache file even if it's wrong
|
||||||
f.close()
|
ensureDirectories(cachefile)
|
||||||
|
f = open(cachefile,'w')
|
||||||
|
f.write(scout)
|
||||||
|
f.close()
|
||||||
|
|
||||||
return (status,scout)
|
return (status,scout)
|
||||||
|
|
||||||
@ -168,11 +185,11 @@ def default_arguments(plist,match,bounds):
|
|||||||
if bounds == 0:
|
if bounds == 0:
|
||||||
timer = nmin**2
|
timer = nmin**2
|
||||||
maxruns = 2*nmin
|
maxruns = 2*nmin
|
||||||
maxlength = 2 + maxruns * 3
|
maxlength = 2 + maxruns * 4
|
||||||
elif bounds == 1:
|
elif bounds == 1:
|
||||||
timer = nmin**3
|
timer = nmin**3
|
||||||
maxruns = 3*nmin
|
maxruns = 3*nmin
|
||||||
maxlength = 2 + maxruns * 4
|
maxlength = 2 + maxruns * 6
|
||||||
else:
|
else:
|
||||||
print "Don't know bounds method", bounds
|
print "Don't know bounds method", bounds
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
Loading…
Reference in New Issue
Block a user