File tree Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Original file line number Diff line number Diff line change 11from __future__ import annotations
22
3- import time
43from typing import TYPE_CHECKING
54
65from typing_extensions import Self # noqa: UP035
76
87if TYPE_CHECKING :
8+ from collections .abc import Callable
99 from types import TracebackType
1010
1111
1212class ContextTimer :
13- def __init__ (self ) -> None :
13+ def __init__ (self , measure_func : Callable [..., float ]) -> None :
14+ self .measure_func = measure_func
1415 self .execution_time = 0.0
1516 self .all_execution_times : list [float ] = []
1617 self .exec_times_per_iter : list [float ] = []
@@ -24,7 +25,7 @@ def queries_count_per_iter(self) -> int:
2425 return len (self .exec_times_per_iter )
2526
2627 def __enter__ (self ) -> Self :
27- self ._start = time . monotonic ()
28+ self ._start = self . measure_func ()
2829 return self
2930
3031 def __exit__ (
@@ -36,7 +37,7 @@ def __exit__(
3637 if exc_type is not None :
3738 return
3839
39- self ._end = time . monotonic ()
40+ self ._end = self . measure_func ()
4041 self .execution_time = self ._end - self ._start
4142 self .all_execution_times .append (self .execution_time )
4243 self .exec_times_per_iter .append (self .execution_time )
Original file line number Diff line number Diff line change 11from __future__ import annotations
22
33import json
4+ import time
45from typing import TYPE_CHECKING , Any , NamedTuple
56
67from django .utils .regex_helper import _lazy_re_compile
1920
2021class BaseExecutionWrapper :
2122 def __init__ (self , queries_log : QueriesLog , * args : Any , ** kwargs : Any ) -> None :
22- self .timer = ContextTimer ()
23+ self .timer = ContextTimer (time . perf_counter )
2324 self .queries_log = queries_log
2425
2526 def __call__ (
You can’t perform that action at this time.
0 commit comments