iaperftest - Comparação de Performance

Date: 13/04/2013

Código-fonte

 1 import warnings
 2 warnings.simplefilter("ignore")
 3 
 4 import iaOPF.iaperftest
 5 
 6 class PerfTest(iaOPF.iaperftest.PerfTest):
 7     vet_testers = []
 8     vet_funcs = []
 9 
10     def __init__(self):
11         self.vet_tests = []
12         self.vet_fncs = []
13         self.vet_testers = []
14         self.vet_funcs = []
15 
16     def addTester(self, name, fun, args=[]):
17         self.vet_testers.append([name, fun, args])
18 
19     def addTest(self, author, name, fun, args=[], kwargs={}, pprocs=[]):
20         self.vet_funcs.append([author, name, fun, args, kwargs, pprocs])
21 
22     def setLists(self):
23         listF = []
24         listT = []
25         for tname, tester, targs in self.vet_testers:
26             listT.append([tname, (tester, targs)])
27         for author, name, fun, args, kwargs, pprocs in self.vet_funcs:
28             if len(pprocs) == 0:
29                 pprocs = [lambda x,y: y]
30             def myfun(x, fun=fun, args=args, kwargs=kwargs):
31                 tester = x[0]
32                 targs = x[1]
33                 return tester([fun, args, kwargs], *targs)
34             listF.append([author, name, myfun, pprocs])
35         return listF, listT
36 
37     def runTests(self, n=1):
38         listF, self.vet_tests = self.setLists()
39         return iaOPF.iaperftest.PerfTest.runTests(self, listF, n)
40 
41     def showResults(self, listPaginas):
42         _, self.vet_tests = self.setLists()
43         return iaOPF.iaperftest.PerfTest.showResults(self, listPaginas)

Exemplo de Utilização

Página de Definição dos Testes

 1 import ialprPerftest
 2 
 3 tester = ialprPerftest.PerfTest()
 4 tester.setup(xsPackage, xsModule)
 5 
 6 # --------------------------
 7 # Função que executa o teste
 8 # --------------------------
 9 def check_binary(userfun, id):
10     from iaLPR import lprGetPhoto
11     fun, args, kwargs = userfun
12     image, _ = lprGetPhoto(id)
13     return fun(image, *args, **kwargs).dtype == bool
14 
15 # ----------------------
16 # Registra cada testador
17 # ----------------------
18 # def addTester(descr, fun, args=[])
19 
20 tester.addTester('imagem 1', check_binary, [300])
21 tester.addTester('imagem 2', check_binary, [400])
22 tester.addTester('imagem 3', check_binary, [500])

Página de Execução dos Testes

 1 # ------------------------
 2 # Funções a serem testadas
 3 # ------------------------
 4 def binarize(image, t=100):
 5     return image > t
 6 
 7 def binarize2(image, t=100):
 8     return image + t
 9 
10 # -------------------
11 # Registra cada teste
12 # -------------------
13 # def addTest(author, fun_descr, fun, args=[], kwargs={}, postproc=[])
14 
15 tester.addTest('rubens', 'binarize 100',  binarize)
16 tester.addTest('rubens', 'binarize2 100', binarize2)
17 
18 tester.addTest('rubens', 'binarize 150',  binarize, args=[150])
19 tester.addTest('rubens', 'binarize 180',  binarize, kwargs=dict(t=180))
20 tester.addTest('rubens', 'binarize 190',  binarize, [], dict(t=190), [lambda x,y: ['ERROR', 'OK'][y]])
21 tester.addTest('rubens', 'binarize2 290', binarize2, pprocs=[lambda x,y: True])
22 
23 # -----------------
24 # Executa os testes
25 # -----------------
26 vet_result = tester.runTests()

gravando arquivo: /home/rubens/www/media/Attachments/iaLPR/ialprPerftest/testperf.pkl

Autor Funcao imagem 1   imagem 2   imagem 3  
rubens binarize 100 5.529 ms True 1.811 ms True 1.632 ms True
rubens binarize2 100 1.531 ms False 1.5 ms False 1.459 ms False
rubens binarize 150 1.519 ms True 1.52 ms True 1.503 ms True
rubens binarize 180 1.513 ms True 1.531 ms True 1.49 ms True
rubens binarize 190 1.496 ms OK 1.502 ms OK 1.479 ms OK
rubens binarize2 290 1.427 ms True 1.445 ms True 1.417 ms True