Skip to content
Snippets Groups Projects
Commit a5d4c0f6 authored by mads's avatar mads
Browse files

documentation of timing

parent 2bbc5934
No related branches found
No related tags found
No related merge requests found
...@@ -29,3 +29,4 @@ Tools for working with NREL's FAST code (An aeroelastic computer-aided engineeri ...@@ -29,3 +29,4 @@ Tools for working with NREL's FAST code (An aeroelastic computer-aided engineeri
Other functions Other functions
- [geometry](wetb/functions/geometry.py): Different kind of geometry conversion functions - [geometry](wetb/functions/geometry.py): Different kind of geometry conversion functions
- [process_exec](wetb/functions/process_exec.py): Run system command in subprocess - [process_exec](wetb/functions/process_exec.py): Run system command in subprocess
- [timing](wetb/functions/timing.py): Decorators for evaluating execution time of functions
...@@ -2,6 +2,17 @@ from six import exec_ ...@@ -2,6 +2,17 @@ from six import exec_
import time import time
import inspect import inspect
def get_time(f): def get_time(f):
"""Get time decorator
returns (return_values, time_of_execution)
>>> @get_time
>>> def test():
>>> time.sleep(1)
>>> return "end"
>>>
>>> test()
('end', 0.999833492421551)
"""
def wrap(*args, **kwargs): def wrap(*args, **kwargs):
t = time.clock() t = time.clock()
res = f(*args, **kwargs) res = f(*args, **kwargs)
...@@ -12,6 +23,16 @@ def get_time(f): ...@@ -12,6 +23,16 @@ def get_time(f):
def print_time(f): def print_time(f):
"""Print time decorator
prints name of method and time of execution
>>> @print_time
>>> def test():
>>> time.sleep(1)
>>>
>>> test()
test 1.000s
"""
def wrap(*args, **kwargs): def wrap(*args, **kwargs):
t = time.time() t = time.time()
res = f(*args, **kwargs) res = f(*args, **kwargs)
...@@ -24,6 +45,18 @@ def print_time(f): ...@@ -24,6 +45,18 @@ def print_time(f):
cum_time = {} cum_time = {}
def print_cum_time(f): def print_cum_time(f):
"""Print cumulated time decorator
prints name of method and cumulated time of execution
>>> @print_cum_time
>>> def test():
>>> time.sleep(1)
>>>
>>> test()
test 0001 calls, 1.000000s, 1.000000s pr. call'
>>> test()
test 0002 calls, 2.000000s, 1.000000s pr. call'
"""
if f not in cum_time: if f not in cum_time:
cum_time[f] = (0, 0) cum_time[f] = (0, 0)
...@@ -40,6 +73,22 @@ def print_cum_time(f): ...@@ -40,6 +73,22 @@ def print_cum_time(f):
return w return w
def print_line_time(f): def print_line_time(f):
"""Execute one line at the time and prints the time of execution.
Only for non-branching and non-looping code
prints: time_of_line, cumulated_time, code_line
>>> @print_line_time
>>> def test():
>>> time.sleep(.3)
>>> time.sleep(.5)
>>>
>>> test()
0.300s 0.300s time.sleep(.3)
0.510s 0.810s time.sleep(.51)
"""
def wrap(*args, **kwargs): def wrap(*args, **kwargs):
arg_names, varargs, varkw, defaults = inspect.getargspec(f) arg_names, varargs, varkw, defaults = inspect.getargspec(f)
kwargs[varargs] = args[len(arg_names):] kwargs[varargs] = args[len(arg_names):]
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
Created on 20/01/2014 Created on 20/01/2014
@author: MMPE @author: MMPE
See documentation of HTCFile below
''' '''
from collections import OrderedDict from collections import OrderedDict
import os import os
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment