Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 30974:ae5d60bb70c9
util: introduce timer()
As documented for timeit.default_timer, there are better timers available for
performance measures on some platforms. These timers don't have a set epoch,
and thus are only useful for interval measurements, but have higher
resolution, and thus get you a better measurement overall.
Use the same selection logic as Python's timeit.default_timer. This is a
platform clock on Python 2 and early Python 3, and time.perf_counter on Python
3.3 and later (where time.perf_counter is introduced as the best timer to use).
author | Simon Farnsworth <simonfar@fb.com> |
---|---|
date | Wed, 15 Feb 2017 11:53:59 -0800 |
parents | 82f1ef8b4477 |
children | 22fbca1d11ed |
comparison
equal
deleted
inserted
replaced
30973:e5363cb96233 | 30974:ae5d60bb70c9 |
---|---|
1201 return _("filename ends with '%s', which is not allowed " | 1201 return _("filename ends with '%s', which is not allowed " |
1202 "on Windows") % t | 1202 "on Windows") % t |
1203 | 1203 |
1204 if pycompat.osname == 'nt': | 1204 if pycompat.osname == 'nt': |
1205 checkosfilename = checkwinfilename | 1205 checkosfilename = checkwinfilename |
1206 timer = time.clock | |
1206 else: | 1207 else: |
1207 checkosfilename = platform.checkosfilename | 1208 checkosfilename = platform.checkosfilename |
1209 timer = time.time | |
1210 | |
1211 if safehasattr(time, "perf_counter"): | |
1212 timer = time.perf_counter | |
1208 | 1213 |
1209 def makelock(info, pathname): | 1214 def makelock(info, pathname): |
1210 try: | 1215 try: |
1211 return os.symlink(info, pathname) | 1216 return os.symlink(info, pathname) |
1212 except OSError as why: | 1217 except OSError as why: |