Use monotonic clock for interval measurement (#6211)
Signed-off-by: Lifu Huang <lifu.hlf@gmail.com>
This commit is contained in:
@@ -246,7 +246,7 @@ def mark_start(name, interval=0.1, color=0, indent=0):
|
||||
torch.cuda.synchronize()
|
||||
if time_infos.get(name, None) is None:
|
||||
time_infos[name] = TimeInfo(name, interval, color, indent)
|
||||
time_infos[name].acc_time -= time.time()
|
||||
time_infos[name].acc_time -= time.perf_counter()
|
||||
|
||||
|
||||
def mark_end(name):
|
||||
@@ -254,7 +254,7 @@ def mark_end(name):
|
||||
if not show_time_cost:
|
||||
return
|
||||
torch.cuda.synchronize()
|
||||
time_infos[name].acc_time += time.time()
|
||||
time_infos[name].acc_time += time.perf_counter()
|
||||
if time_infos[name].check():
|
||||
time_infos[name].pretty_print()
|
||||
|
||||
@@ -264,11 +264,11 @@ def calculate_time(show=False, min_cost_ms=0.0):
|
||||
def inner_func(*args, **kwargs):
|
||||
torch.cuda.synchronize()
|
||||
if show:
|
||||
start_time = time.time()
|
||||
start_time = time.perf_counter()
|
||||
result = func(*args, **kwargs)
|
||||
torch.cuda.synchronize()
|
||||
if show:
|
||||
cost_time = (time.time() - start_time) * 1000
|
||||
cost_time = (time.perf_counter() - start_time) * 1000
|
||||
if cost_time > min_cost_ms:
|
||||
print(f"Function {func.__name__} took {cost_time} ms to run.")
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user