D4516: contrib: use a monotonic timer in catapipe

lothiraldan (Boris Feld) phabricator at mercurial-scm.org
Sat Sep 8 10:08:09 UTC 2018


lothiraldan created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  As spotted by Gregory, we should use a monotonic timer to get better timings.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4516

AFFECTED FILES
  contrib/catapipe.py

CHANGE DETAILS

diff --git a/contrib/catapipe.py b/contrib/catapipe.py
--- a/contrib/catapipe.py
+++ b/contrib/catapipe.py
@@ -29,17 +29,21 @@
 from __future__ import absolute_import, print_function
 
 import argparse
-import datetime
 import json
 import os
+import timeit
 
 _TYPEMAP = {
     'START': 'B',
     'END': 'E',
 }
 
 _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)



To: lothiraldan, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list