Moves timer to statistics utilities.

This commit is contained in:
Romain Dorgueil
2017-11-04 15:01:04 +01:00
parent 0b969d31e0
commit 8439a535fe
2 changed files with 21 additions and 21 deletions

View File

@ -13,6 +13,7 @@
# without warranties or conditions of any kind, either express or implied.
# see the license for the specific language governing permissions and
# limitations under the license.
import time
class WithStatistics:
@ -29,3 +30,23 @@ class WithStatistics:
def increment(self, name):
self.statistics[name] += 1
class Timer:
"""
Context manager used to time execution of stuff.
"""
def __enter__(self):
self.__start = time.time()
def __exit__(self, type=None, value=None, traceback=None):
# Error handling here
self.__finish = time.time()
@property
def duration(self):
return self.__finish - self.__start
def __str__(self):
return str(int(self.duration * 1000) / 1000.0) + 's'

View File

@ -1,21 +0,0 @@
import time
class Timer:
"""
Context manager used to time execution of stuff.
"""
def __enter__(self):
self.__start = time.time()
def __exit__(self, type=None, value=None, traceback=None):
# Error handling here
self.__finish = time.time()
@property
def duration(self):
return self.__finish - self.__start
def __str__(self):
return str(int(self.duration * 1000) / 1000.0) + 's'