Update of /cvsroot/webware/Webware/MiscUtils/Testing
In directory usw-pr-cvs1:/tmp/cvs-serv2958
Added Files:
.cvsignore BenchCSVParser.py BenchDataTable.py Sample1.csv
Log Message:
added some benchmarking programs. useful for profiling
--- NEW FILE: .cvsignore ---
*.pstats
--- NEW FILE: BenchCSVParser.py ---
#!/usr/bin/env python
import FixPath
from glob import glob
from CSVParser import CSVParser
from profile import Profile
import sys, time
class BenchCSVParser:
def __init__(self, profile=0, runTestSuite=1):
self.parse = CSVParser().parse
self._shouldProfile = profile
self._shouldRunTestSuite = runTestSuite
self._iters = 100
def main(self):
if len(sys.argv)>1 and sys.argv[1].lower().startswith('prof'):
self._shouldProfile = 1
if self._shouldRunTestSuite:
from TestCSVParser import main
main()
start = time.time()
if self._shouldProfile:
prof = Profile()
prof.runcall(self._main)
filename = '%s.pstats' % self.__class__.__name__
prof.dump_stats(filename)
print 'Wrote', filename
else:
self._main()
duration = time.time() - start
print '%.1f secs' % duration
def _main(self):
for name in glob('Sample*.csv'):
self.benchFileNamed(name)
def benchFileNamed(self, name):
lines = open(name).readlines()
for line in lines:
for x in xrange(self._iters):
# we duplicate lines to reduce the overhead of the loop
self.parse(line)
self.parse(line)
self.parse(line)
self.parse(line)
self.parse(line)
self.parse(line)
self.parse(line)
self.parse(line)
self.parse(line)
self.parse(line)
self.parse(line)
self.parse(line)
self.parse(line)
self.parse(line)
self.parse(line)
self.parse(line)
if __name__=='__main__':
BenchCSVParser().main()
--- NEW FILE: BenchDataTable.py ---
#!/usr/bin/env python
import FixPath
from glob import glob
from DataTable import DataTable
from profile import Profile
import sys, time
class BenchDataTable:
def __init__(self, profile=1, runTestSuite=1):
self._shouldProfile = profile
self._shouldRunTestSuite = runTestSuite
self._iters = 200
def main(self):
if len(sys.argv)>1 and sys.argv[1].lower().startswith('prof'):
self._shouldProfile = 1
if self._shouldRunTestSuite:
from TestDataTable import main
main()
start = time.time()
if self._shouldProfile:
prof = Profile()
prof.runcall(self._main)
filename = '%s.pstats' % self.__class__.__name__
prof.dump_stats(filename)
print 'Wrote', filename
else:
self._main()
duration = time.time() - start
print '%.1f secs' % duration
def _main(self):
for name in glob('Sample*.csv'):
self.benchFileNamed(name)
def benchFileNamed(self, name):
contents = open(name).read()
for x in xrange(self._iters):
# we duplicate lines to reduce the overhead of the loop
dt = DataTable()
dt.readString(contents)
dt = DataTable()
dt.readString(contents)
dt = DataTable()
dt.readString(contents)
dt = DataTable()
dt.readString(contents)
dt = DataTable()
dt.readString(contents)
dt = DataTable()
dt.readString(contents)
dt = DataTable()
dt.readString(contents)
dt = DataTable()
dt.readString(contents)
if __name__=='__main__':
BenchDataTable().main()
--- NEW FILE: Sample1.csv ---
Class,Attribute,Type,isRequired,Min,Max,Extras
Video,,,,,,isAbstract=1
,title,string,1,1,100,
,directors,list of Person,0,,10,
,cast,list of Role,0,,,
Movie (Video),,,,,,
,year,int,1,,,
,rating,enum,1,,,"Enums='g, pg, pg13, r, nc17, x, nr, other'"
TVSeries (Video),,,,,,
,years,int,,,,Comment='@@ supposed to be pickle; a list of ints'
Person,,,,,,
,video,Video,0,,,Comment='back pointer to View for directors attr'
,name,string,1,1,100,
,birthDate,date,0,,50,
Role,,,,,,
,video,Video,1,,,
,karacter,string,1,,100
,person,Person,1,,
|