Skip to content

Commit 083e2b2

Browse files
authored
Merge pull request #3557 from bdarnell/perf-counter-65
branch6.5: Use time.perf_counter instead of time.time for performance tests
2 parents 2976629 + 31431c9 commit 083e2b2

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

docs/caresresolver.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ wrapper ``pycares``).
1919
the default for ``tornado.simple_httpclient``, but other libraries
2020
may default to ``AF_UNSPEC``.
2121

22+
This class requires ``pycares`` version 4. Since this class is deprecated, it will not be
23+
updated to support ``pycares`` version 5.
24+
2225
.. deprecated:: 6.2
2326
This class is deprecated and will be removed in Tornado 7.0. Use the default
2427
thread-based resolver instead.

tornado/test/httputil_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def test_disposition_param_linear_performance(self):
284284
# to the content-disposition header, specifically for semicolons within
285285
# quoted strings.
286286
def f(n):
287-
start = time.time()
287+
start = time.perf_counter()
288288
message = (
289289
b"--1234\r\nContent-Disposition: form-data; "
290290
+ b'x="'
@@ -295,7 +295,7 @@ def f(n):
295295
args: dict[str, list[bytes]] = {}
296296
files: dict[str, list[HTTPFile]] = {}
297297
parse_multipart_form_data(b"1234", message, args, files)
298-
return time.time() - start
298+
return time.perf_counter() - start
299299

300300
d1 = f(1_000)
301301
d2 = f(10_000)
@@ -496,11 +496,11 @@ def test_invalid_header_names(self):
496496

497497
def test_linear_performance(self):
498498
def f(n):
499-
start = time.time()
499+
start = time.perf_counter()
500500
headers = HTTPHeaders()
501501
for i in range(n):
502502
headers.add("X-Foo", "bar")
503-
return time.time() - start
503+
return time.perf_counter() - start
504504

505505
# This runs under 50ms on my laptop as of 2025-12-09.
506506
d1 = f(10_000)

tox.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ basepython =
3535
deps =
3636
full: pycurl
3737
full: twisted
38-
full: pycares
38+
# Pycares 5 has some backwards-incompatible changes that we don't support.
39+
# And since CaresResolver is deprecated, I do not expect to fix it, so just
40+
# pin the previous version. (This should really be in requirements.{in,txt} instead)
41+
full: pycares<5
3942
docs: -r{toxinidir}/requirements.txt
4043
lint: -r{toxinidir}/requirements.txt
4144

0 commit comments

Comments
 (0)