]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Use time.perf_counter() for cache time measurement
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 24 Jun 2020 23:47:52 +0000 (19:47 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 25 Jun 2020 01:16:58 +0000 (21:16 -0400)
See https://twitter.com/raymondh/status/1275937373080023040

Change-Id: Iaa0abb0c433ccedfbd88d00e3970120242ba379b

lib/sqlalchemy/engine/default.py
lib/sqlalchemy/sql/compiler.py
lib/sqlalchemy/util/__init__.py
lib/sqlalchemy/util/compat.py

index 1a8dbb4cda76d7882920b733d4de8b89f9b0186a..cef7194981748fa564f32c2299d43f737e716d59 100644 (file)
@@ -16,7 +16,6 @@ as the base class for their own corresponding classes.
 import codecs
 import random
 import re
-import time
 import weakref
 
 from . import cursor as _cursor
@@ -1027,7 +1026,7 @@ class DefaultExecutionContext(interfaces.ExecutionContext):
         if self.compiled is None:
             return "raw sql"
 
-        now = time.time()
+        now = util.perf_counter()
         if self.compiled.cache_key is None:
             return "no key %.5fs" % (now - self.compiled._gen_time,)
         elif self.cache_hit:
index 61178291ad2d066f458b463c35e4b002eaf58e72..b5e85ffb86f25358250301cc2026b881437713a7 100644 (file)
@@ -28,7 +28,6 @@ import contextlib
 import itertools
 import operator
 import re
-import time
 
 from . import base
 from . import coercions
@@ -482,7 +481,7 @@ class Compiled(object):
                 self.string = self.preparer._render_schema_translates(
                     self.string, schema_translate_map
                 )
-        self._gen_time = time.time()
+        self._gen_time = util.perf_counter()
 
     def _execute_on_connection(
         self, connection, multiparams, params, execution_options
index 273570357b09f600df0913bd840eed8f0a4f6efe..fb90975a185eda7a9705c77154b68c121184edfc 100644 (file)
@@ -61,6 +61,7 @@ from .compat import itertools_filterfalse  # noqa
 from .compat import namedtuple  # noqa
 from .compat import next  # noqa
 from .compat import parse_qsl  # noqa
+from .compat import perf_counter  # noqa
 from .compat import pickle  # noqa
 from .compat import print_  # noqa
 from .compat import py2k  # noqa
index 5c46395f9a1e0d780a133ed16186308b77ec4868..806ef8ae18249f1f4f957ecdaca738eaf9b3f7a2 100644 (file)
@@ -99,6 +99,7 @@ if py3k:
     from io import BytesIO as byte_buffer
     from io import StringIO
     from itertools import zip_longest
+    from time import perf_counter
     from urllib.parse import (
         quote_plus,
         unquote_plus,
@@ -192,6 +193,7 @@ else:
     from StringIO import StringIO  # noqa
     from cStringIO import StringIO as byte_buffer  # noqa
     from itertools import izip_longest as zip_longest  # noqa
+    from time import clock as perf_counter  # noqa
     from urllib import quote  # noqa
     from urllib import quote_plus  # noqa
     from urllib import unquote  # noqa