pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/pre-commit/pre-commit/commit/d988767b414495bdab9ea24532ad337e8ee3fd1f

ef="https://github.githubassets.com/assets/global-d18f184ea1a06a2c.css" /> Improve hook duration timing · pre-commit/pre-commit@d988767 · GitHub
Skip to content

Commit d988767

Browse files
committed
Improve hook duration timing
1 parent ac42dc5 commit d988767

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

pre_commit/commands/run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def _run_single_hook(
187187

188188
if not hook.pass_filenames:
189189
filenames = ()
190-
time_before = time.time()
190+
time_before = time.monotonic()
191191
language = languages[hook.language]
192192
with language.in_env(hook.prefix, hook.language_version):
193193
retcode, out = language.run_hook(
@@ -199,7 +199,7 @@ def _run_single_hook(
199199
require_serial=hook.require_serial,
200200
color=use_color,
201201
)
202-
duration = round(time.time() - time_before, 2) or 0
202+
duration = round(time.monotonic() - time_before, 2) or 0
203203
diff_after = _get_diff()
204204

205205
# if the hook makes changes, fail the commit

tests/commands/run_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def test_verbose_duration(cap_out, store, in_git_dir, t1, t2, expected):
293293
write_config('.', {'repo': 'meta', 'hooks': [{'id': 'identity'}]})
294294
cmd_output('git', 'add', '.')
295295
opts = run_opts(verbose=True)
296-
with mock.patch.object(time, 'time', side_effect=(t1, t2)):
296+
with mock.patch.object(time, 'monotonic', side_effect=(t1, t2)):
297297
ret, printed = _do_run(cap_out, store, str(in_git_dir), opts)
298298
assert ret == 0
299299
assert expected in printed

tests/commands/try_repo_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def _run_try_repo(tempdir_factory, **kwargs):
4343

4444

4545
def test_try_repo_repo_only(cap_out, tempdir_factory):
46-
with mock.patch.object(time, 'time', return_value=0.0):
46+
with mock.patch.object(time, 'monotonic', return_value=0.0):
4747
_run_try_repo(tempdir_factory, verbose=True)
4848
start, config, rest = _get_out(cap_out)
4949
assert start == ''

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy