Changeset 3041 for trunk/GSASIIobj.py


Ignore:
Timestamp:
Sep 3, 2017 11:18:33 AM (4 years ago)
Author:
toby
Message:

Fully implement multiprocessing on reflection loops, but currently disabled, when enabled default is still not to use unless turned on in config; add timing code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIobj.py

    r3023 r3041  
    27072707    return Id
    27082708
     2709class ShowTiming(object):
     2710    '''An object to use for timing repeated sections of code.
     2711
     2712    Create the object with::
     2713       tim0 = ShowTiming()
     2714
     2715    Tag sections of code to be timed with::
     2716       tim0.start('start')
     2717       tim0.start('in section 1')
     2718       tim0.start('in section 2')
     2719    etc. (Note that each section should have a unique label.)
     2720
     2721    After the last section, end timing with::
     2722       tim0.end()
     2723
     2724    Show timing results with::
     2725       tim0.show()
     2726       
     2727    '''
     2728    def __init__(self):
     2729        self.timeSum =  []
     2730        self.timeStart = []
     2731        self.label = []
     2732        self.prev = None
     2733    def start(self,label):
     2734        if label in self.label:
     2735            i = self.label.index(label)
     2736            self.timeStart[i] = time.time()
     2737        else:
     2738            i = len(self.label)
     2739            self.timeSum.append(0.0)
     2740            self.timeStart.append(time.time())
     2741            self.label.append(label)
     2742        if self.prev is not None:
     2743            self.timeSum[self.prev] += self.timeStart[i] - self.timeStart[self.prev]
     2744        self.prev = i
     2745    def end(self):
     2746        if self.prev is not None:
     2747            self.timeSum[self.prev] += time.time() - self.timeStart[self.prev]
     2748        self.prev = None
     2749    def show(self):
     2750        sumT = sum(self.timeSum)
     2751        print('Timing results (total={:.2f} sec)'.format(sumT))
     2752        for i,(lbl,val) in enumerate(zip(self.label,self.timeSum)):
     2753            print('{} {:20} {:8.2f} ms {:5.2f}%'.format(i,lbl,1000.*val,100*val/sumT))
     2754
    27092755
    27102756if __name__ == "__main__":
Note: See TracChangeset for help on using the changeset viewer.