Skip to content

Use time.perf_counter_ns #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions codewars_test/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,19 @@ def it1():


def _timed_block_factory(opening_text):
from timeit import default_timer as timer
from time import perf_counter_ns as timer
from traceback import format_exception
from sys import exc_info

millis_per_nano = 1_000_000

def _timed_block_decorator(s, before=None, after=None):
display(opening_text, s)

def wrapper(func):
if callable(before):
before()
time = timer()
time_ns = timer()
try:
func()
except AssertionError as e:
Expand All @@ -116,7 +118,7 @@ def wrapper(func):
fail('Unexpected exception raised')
tb_str = ''.join(format_exception(*exc_info()))
display('ERROR', tb_str)
display('COMPLETEDIN', '{:.2f}'.format((timer() - time) * 1000))
display('COMPLETEDIN', '{:.2f}'.format((timer() - time_ns) / millis_per_nano))
if callable(after):
after()
return wrapper
Expand Down