Project

General

Profile

« Previous | Next » 

Revision 1042

profiling.py: Support Python before 2.7 by using new dates.total_seconds(). Also use dates.now() to ensure datetimes always have a timezone.

View differences:

lib/profiling.py
3 3
import sys
4 4
import datetime
5 5

  
6
import dates
6 7
import format
7 8

  
8
def now(): return datetime.datetime.now()
9

  
10 9
class Profiler:
11 10
    def __init__(self, start_now=False):
12 11
        self.total = datetime.timedelta()
13 12
        if start_now: self.start()
14 13
    
15
    def start(self): self.start = now()
14
    def start(self): self.start = dates.now()
16 15
    
17 16
    def stop(self):
18 17
        assert self.start != None
19
        self.total += now() - self.start
18
        self.total += dates.now() - self.start
20 19
    
21 20
    def msg(self): return 'Took '+str(self.total)+' sec'
22 21

  
......
38 37
        msg = Profiler.msg(self)
39 38
        if self.iter_ct != None:
40 39
            msg += ('/'+format.int2str(self.iter_ct)+' '+self.iter_text+'(s) = '
41
            +format.to_si(float(self.total.total_seconds())/self.iter_ct)
40
            +format.to_si(float(dates.total_seconds(self.total))/self.iter_ct)
42 41
            +'s/'+self.iter_text)
43 42
        return msg

Also available in: Unified diff