-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement test timing, to allow testing of how much each test takes.
Can be used to compare timings on different hardware, as well as checking if the timings apply to the ones specified in EEP. Currently only run with timings, when environment variable `WITH_TIMINGS` is set, as these tests can take some time to run...
- Loading branch information
Showing
7 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
WITH_TIMINGS=1 nosetests -s -q |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# -*- encoding: utf-8 -*- | ||
from __future__ import print_function, unicode_literals, division | ||
import time | ||
import functools | ||
from os import environ | ||
|
||
|
||
def timing(rounds=1, limit=None): | ||
''' | ||
Wrapper to implement simple timing of tests. | ||
Allows running multiple rounds to calculate average time. | ||
Limit (in milliseconds) can be set to assert, if (average) duration is too high. | ||
''' | ||
def decorator(method): | ||
@functools.wraps(method) | ||
def f(): | ||
if rounds == 1: | ||
start = time.time() | ||
method() | ||
duration = time.time() - start | ||
else: | ||
start = time.time() | ||
for i in range(rounds): | ||
method() | ||
duration = (time.time() - start) / rounds | ||
# Use milliseconds for duration counter | ||
duration = duration * 1e3 | ||
|
||
print('Test "%s.%s" took %.06f ms.' % (method.__module__, method.__name__, duration)) | ||
if limit is not None: | ||
assert limit > duration, 'Timing failure: %.06f > %.06f' % (duration, limit) | ||
|
||
# Run tests with timings, only if WITH_TIMINGS environment variable is set. | ||
# This is because tests with multiple rounds can take long to process. | ||
if environ.get('WITH_TIMINGS', None) is '1': | ||
return method | ||
return f | ||
return decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters