From: Ben Darnell Date: Thu, 11 Dec 2025 03:00:03 +0000 (-0500) Subject: test: Use time.perf_counter instead of time.time for performance tests X-Git-Tag: v6.5.3~1^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31431c9aecefeb64b4c2fddcff5a25eccc12e981;p=thirdparty%2Ftornado.git test: Use time.perf_counter instead of time.time for performance tests On windows, time.time has low resolution (about 15ms), which makes performance tests flaky. time.perf_counter has much higher resolution and is the recommended way to measure elapsed time. --- diff --git a/tornado/test/httputil_test.py b/tornado/test/httputil_test.py index 70ccbe1d..655ef7fb 100644 --- a/tornado/test/httputil_test.py +++ b/tornado/test/httputil_test.py @@ -284,7 +284,7 @@ Foo # to the content-disposition header, specifically for semicolons within # quoted strings. def f(n): - start = time.time() + start = time.perf_counter() message = ( b"--1234\r\nContent-Disposition: form-data; " + b'x="' @@ -295,7 +295,7 @@ Foo args: dict[str, list[bytes]] = {} files: dict[str, list[HTTPFile]] = {} parse_multipart_form_data(b"1234", message, args, files) - return time.time() - start + return time.perf_counter() - start d1 = f(1_000) d2 = f(10_000) @@ -496,11 +496,11 @@ Foo: even def test_linear_performance(self): def f(n): - start = time.time() + start = time.perf_counter() headers = HTTPHeaders() for i in range(n): headers.add("X-Foo", "bar") - return time.time() - start + return time.perf_counter() - start # This runs under 50ms on my laptop as of 2025-12-09. d1 = f(10_000)