Changeset 2548 for trunk/testDeriv.py


Ignore:
Timestamp:
Nov 25, 2016 12:44:43 PM (7 years ago)
Author:
vondreele
Message:

put profiler into testDeriv.py

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/testDeriv.py

    r2539 r2548  
    2323import time
    2424import cPickle
     25import cProfile,pstats,StringIO
    2526import wx
    2627import numpy as np
     
    156157        def test1():
    157158            fplot = self.plotNB.add('function test').gca()
     159            pr = cProfile.Profile()
     160            pr.enable()
    158161            M = G2stMth.errRefine(self.values,self.HistoPhases,
    159162                self.parmDict,self.varylist,self.calcControls,
    160163                self.pawleyLookup,None)
     164            pr.disable()
     165            s = StringIO.StringIO()
     166            sortby = 'tottime'
     167            ps = pstats.Stats(pr, stream=s).strip_dirs().sort_stats(sortby)
     168            print 'Profiler of function calculation; top 50% of routines:'
     169            ps.print_stats("GSASII",.5)
     170            print s.getvalue()
    161171            fplot.plot(M,'r',label='M')
    162172            fplot.legend(loc='best')
    163173           
    164         def test2(name,delt):
     174        def test2(name,delt,doProfile):
    165175            Title = 'derivatives test for '+name
    166176            varyList = self.varylist+self.depVarList
    167177            hplot = self.plotNB.add(Title).gca()
     178            if doProfile:
     179                pr = cProfile.Profile()
     180                pr.enable()
    168181            dMdV = G2stMth.dervRefine(self.values,self.HistoPhases,self.parmDict,
    169182                varyList,self.calcControls,self.pawleyLookup,None)
     183            if doProfile:
     184                pr.disable()
     185                s = StringIO.StringIO()
     186                sortby = 'tottime'
     187                ps = pstats.Stats(pr, stream=s).strip_dirs().sort_stats(sortby)
     188                ps.print_stats("GSASII",.5)
     189                print 'Profiler of '+name+' derivative calculation; top 50% of routines:'
     190                print s.getvalue()
    170191            M2 = dMdV[varyList.index(name)]
    171192            hplot.plot(M2,'b',label='analytic deriv')
     
    200221        while self.plotNB.nb.GetPageCount():
    201222            self.plotNB.nb.DeletePage(0)
     223           
    202224        test1()
     225
     226        doProfile = True
    203227        for use,name,delt in zip(self.use,self.varylist+self.depVarList,self.delt):
    204228            if use:
    205                 test2(name,delt)
     229                test2(name,delt,doProfile)
     230                doProfile = False
    206231       
    207232        self.plotNB.Show()
Note: See TracChangeset for help on using the changeset viewer.