Moves timer to statistics utilities.
This commit is contained in:
@ -13,6 +13,7 @@
|
|||||||
# without warranties or conditions of any kind, either express or implied.
|
# without warranties or conditions of any kind, either express or implied.
|
||||||
# see the license for the specific language governing permissions and
|
# see the license for the specific language governing permissions and
|
||||||
# limitations under the license.
|
# limitations under the license.
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
class WithStatistics:
|
class WithStatistics:
|
||||||
@ -29,3 +30,23 @@ class WithStatistics:
|
|||||||
|
|
||||||
def increment(self, name):
|
def increment(self, name):
|
||||||
self.statistics[name] += 1
|
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'
|
||||||
|
|||||||
@ -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'
|
|
||||||
Reference in New Issue
Block a user