Mercurial > hg
comparison contrib/hgperf @ 30975:22fbca1d11ed
mercurial: switch to util.timer for all interval timings
util.timer is now the best available interval timer, at the expense of not
having a known epoch. Let's use it whenever the epoch is irrelevant.
author | Simon Farnsworth <simonfar@fb.com> |
---|---|
date | Wed, 15 Feb 2017 13:17:39 -0800 |
parents | 377a111d1cd2 |
children | 78f644fdaa2a |
comparison
equal
deleted
inserted
replaced
30974:ae5d60bb70c9 | 30975:22fbca1d11ed |
---|---|
53 sys.exit(-1) | 53 sys.exit(-1) |
54 | 54 |
55 import mercurial.util | 55 import mercurial.util |
56 import mercurial.dispatch | 56 import mercurial.dispatch |
57 | 57 |
58 import time | |
59 | |
60 def timer(func, title=None): | 58 def timer(func, title=None): |
61 results = [] | 59 results = [] |
62 begin = time.time() | 60 begin = mercurial.util.timer() |
63 count = 0 | 61 count = 0 |
64 while True: | 62 while True: |
65 ostart = os.times() | 63 ostart = os.times() |
66 cstart = time.time() | 64 cstart = mercurial.util.timer() |
67 r = func() | 65 r = func() |
68 cstop = time.time() | 66 cstop = mercurial.util.timer() |
69 ostop = os.times() | 67 ostop = os.times() |
70 count += 1 | 68 count += 1 |
71 a, b = ostart, ostop | 69 a, b = ostart, ostop |
72 results.append((cstop - cstart, b[0] - a[0], b[1]-a[1])) | 70 results.append((cstop - cstart, b[0] - a[0], b[1]-a[1])) |
73 if cstop - begin > 3 and count >= 100: | 71 if cstop - begin > 3 and count >= 100: |