changeset 39531:b29ec19748a7

contrib: use a monotonic timer in catapipe As spotted by Gregory, we should use a monotonic timer to get better timings. Differential Revision: https://phab.mercurial-scm.org/D4516
author Boris Feld <boris.feld@octobus.net>
date Fri, 07 Sep 2018 17:54:55 -0400
parents e9706686451b
children 93486cc46125
files contrib/catapipe.py
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/catapipe.py	Fri Sep 07 17:51:07 2018 -0400
+++ b/contrib/catapipe.py	Fri Sep 07 17:54:55 2018 -0400
@@ -29,9 +29,9 @@
 from __future__ import absolute_import, print_function
 
 import argparse
-import datetime
 import json
 import os
+import timeit
 
 _TYPEMAP = {
     'START': 'B',
@@ -40,6 +40,10 @@
 
 _threadmap = {}
 
+# Timeit already contains the whole logic about which timer to use based on
+# Python version and OS
+timer = timeit.default_timer
+
 def main():
     parser = argparse.ArgumentParser()
     parser.add_argument('pipe', type=str, nargs=1,
@@ -55,12 +59,12 @@
     try:
         with open(fn) as f, open(args.output, 'w') as out:
             out.write('[\n')
-            start = datetime.datetime.now()
+            start = timer()
             while True:
                 ev = f.readline().strip()
                 if not ev:
                     continue
-                now = datetime.datetime.now()
+                now = timer()
                 if args.debug:
                     print(ev)
                 verb, session, label = ev.split(' ', 2)