mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Upgrade timeit module from Python 3.14.2 (#6854)
--------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -27,3 +27,4 @@ Lib/site-packages/*
|
||||
Lib/test/data/*
|
||||
!Lib/test/data/README
|
||||
cpython/
|
||||
|
||||
|
||||
8
Lib/test/test_timeit.py
vendored
8
Lib/test/test_timeit.py
vendored
@@ -222,8 +222,8 @@ class TestTimeit(unittest.TestCase):
|
||||
def assert_exc_string(self, exc_string, expected_exc_name):
|
||||
exc_lines = exc_string.splitlines()
|
||||
self.assertGreater(len(exc_lines), 2)
|
||||
self.assertTrue(exc_lines[0].startswith('Traceback'))
|
||||
self.assertTrue(exc_lines[-1].startswith(expected_exc_name))
|
||||
self.assertStartsWith(exc_lines[0], 'Traceback')
|
||||
self.assertStartsWith(exc_lines[-1], expected_exc_name)
|
||||
|
||||
def test_print_exc(self):
|
||||
s = io.StringIO()
|
||||
@@ -297,9 +297,7 @@ class TestTimeit(unittest.TestCase):
|
||||
@unittest.skipIf(sys.flags.optimize >= 2, "need __doc__")
|
||||
def test_main_help(self):
|
||||
s = self.run_main(switches=['-h'])
|
||||
# Note: It's not clear that the trailing space was intended as part of
|
||||
# the help text, but since it's there, check for it.
|
||||
self.assertEqual(s, timeit.__doc__ + ' ')
|
||||
self.assertEqual(s, timeit.__doc__)
|
||||
|
||||
def test_main_verbose(self):
|
||||
s = self.run_main(switches=['-v'])
|
||||
|
||||
28
Lib/timeit.py
vendored
Executable file → Normal file
28
Lib/timeit.py
vendored
Executable file → Normal file
@@ -1,5 +1,3 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
"""Tool for measuring execution time of small code snippets.
|
||||
|
||||
This module avoids a number of common traps for measuring execution
|
||||
@@ -46,7 +44,6 @@ Functions:
|
||||
timeit(string, string) -> float
|
||||
repeat(string, string) -> list
|
||||
default_timer() -> float
|
||||
|
||||
"""
|
||||
|
||||
import gc
|
||||
@@ -175,15 +172,20 @@ class Timer:
|
||||
"""
|
||||
it = itertools.repeat(None, number)
|
||||
# XXX RUSTPYTHON TODO: gc module implementation
|
||||
# gcold = gc.isenabled()
|
||||
# gc.disable()
|
||||
# try:
|
||||
# timing = self.inner(it, self.timer)
|
||||
# finally:
|
||||
# if gcold:
|
||||
# gc.enable()
|
||||
# return timing
|
||||
return self.inner(it, self.timer)
|
||||
try:
|
||||
gcold = gc.isenabled()
|
||||
gc.disable()
|
||||
except NotImplementedError:
|
||||
gcold = False
|
||||
try:
|
||||
timing = self.inner(it, self.timer)
|
||||
finally:
|
||||
if gcold:
|
||||
try:
|
||||
gc.enable()
|
||||
except NotImplementedError:
|
||||
pass
|
||||
return timing
|
||||
|
||||
def repeat(self, repeat=default_repeat, number=default_number):
|
||||
"""Call timeit() a few times.
|
||||
@@ -306,7 +308,7 @@ def main(args=None, *, _wrap_timer=None):
|
||||
precision += 1
|
||||
verbose += 1
|
||||
if o in ("-h", "--help"):
|
||||
print(__doc__, end=' ')
|
||||
print(__doc__, end="")
|
||||
return 0
|
||||
setup = "\n".join(setup) or "pass"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user