Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WindEnergyToolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wtlib
WindEnergyToolbox
Commits
a5d4c0f6
Commit
a5d4c0f6
authored
9 years ago
by
mads
Browse files
Options
Downloads
Patches
Plain Diff
documentation of timing
parent
2bbc5934
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+1
-0
1 addition, 0 deletions
README.md
wetb/functions/timing.py
+96
-47
96 additions, 47 deletions
wetb/functions/timing.py
wetb/hawc2/htc_file.py
+3
-0
3 additions, 0 deletions
wetb/hawc2/htc_file.py
with
100 additions
and
47 deletions
README.md
+
1
−
0
View file @
a5d4c0f6
...
@@ -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
This diff is collapsed.
Click to expand it.
wetb/functions/timing.py
+
96
−
47
View file @
a5d4c0f6
...
@@ -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,56 +23,94 @@ def get_time(f):
...
@@ -12,56 +23,94 @@ def get_time(f):
def
print_time
(
f
):
def
print_time
(
f
):
def
wrap
(
*
args
,
**
kwargs
):
"""
Print time decorator
t
=
time
.
time
()
prints name of method and time of execution
res
=
f
(
*
args
,
**
kwargs
)
print
(
"
%-12s
\t
%.3fs
"
%
(
f
.
__name__
,
time
.
time
()
-
t
))
>>>
@print_time
return
res
>>>
def
test
():
w
=
wrap
>>>
time
.
sleep
(
1
)
w
.
__name__
=
f
.
__name__
>>>
return
w
>>>
test
()
test
1.000
s
"""
def
wrap
(
*
args
,
**
kwargs
):
t
=
time
.
time
()
res
=
f
(
*
args
,
**
kwargs
)
print
(
"
%-12s
\t
%.3fs
"
%
(
f
.
__name__
,
time
.
time
()
-
t
))
return
res
w
=
wrap
w
.
__name__
=
f
.
__name__
return
w
cum_time
=
{}
cum_time
=
{}
def
print_cum_time
(
f
):
def
print_cum_time
(
f
):
if
f
not
in
cum_time
:
"""
Print cumulated time decorator
cum_time
[
f
]
=
(
0
,
0
)
prints name of method and cumulated time of execution
def
wrap
(
*
args
,
**
kwargs
):
>>>
@print_cum_time
t
=
time
.
time
()
>>>
def
test
():
res
=
f
(
*
args
,
**
kwargs
)
>>>
time
.
sleep
(
1
)
ct
=
cum_time
[
f
][
1
]
+
time
.
time
()
-
t
>>>
n
=
cum_time
[
f
][
0
]
+
1
>>>
test
()
cum_time
[
f
]
=
(
n
,
ct
)
test
0001
calls
,
1.000000
s
,
1.000000
s
pr
.
call
'
print
(
"
%-12s
\t
%.4d calls, %03fs, %fs pr. call
'"
%
(
f
.
__name__
,
n
,
ct
,
ct
/
n
))
>>>
test
()
return
res
test
0002
calls
,
2.000000
s
,
1.000000
s
pr
.
call
'
w
=
wrap
"""
w
.
__name__
=
f
.
__name__
if f not in cum_time:
return
w
cum_time[f] = (0, 0)
def wrap(*args, **kwargs):
t = time.time()
res = f(*args, **kwargs)
ct = cum_time[f][1] + time.time() - t
n = cum_time[f][0] + 1
cum_time[f] = (n, ct)
print (
"
%-12s
\t
%.4d calls, %03fs, %fs pr. call
'"
% (f.__name__, n, ct, ct / n))
return res
w = wrap
w.__name__ = f.__name__
return w
def print_line_time(f):
def print_line_time(f):
def
wrap
(
*
args
,
**
kwargs
):
"""
Execute one line at the time and prints the time of execution.
arg_names
,
varargs
,
varkw
,
defaults
=
inspect
.
getargspec
(
f
)
Only for non-branching and non-looping code
kwargs
[
varargs
]
=
args
[
len
(
arg_names
):]
kwargs
[
varkw
]
=
{}
prints: time_of_line, cumulated_time, code_line
for
k
,
v
in
kwargs
.
items
():
if
k
not
in
tuple
(
arg_names
)
+
(
varargs
,
varkw
):
kwargs
.
pop
(
k
)
>>>
@print_line_time
kwargs
[
varkw
][
k
]
=
v
>>>
def
test
():
if
defaults
:
>>>
time
.
sleep
(.
3
)
kwargs
.
update
(
dict
(
zip
(
arg_names
[::
-
1
],
defaults
[::
-
1
])))
>>>
time
.
sleep
(.
5
)
kwargs
.
update
(
dict
(
zip
(
arg_names
,
args
)))
>>>
>>>
test
()
0.300
s
0.300
s
time
.
sleep
(.
3
)
lines
=
inspect
.
getsourcelines
(
f
)[
0
][
2
:]
0.510
s
0.810
s
time
.
sleep
(.
51
)
tcum
=
time
.
clock
()
locals
=
kwargs
"""
gl
=
f
.
__globals__
def wrap(*args, **kwargs):
arg_names, varargs, varkw, defaults = inspect.getargspec(f)
for
l
in
lines
:
kwargs[varargs] = args[len(arg_names):]
tline
=
time
.
clock
()
kwargs[varkw] = {}
exec
(
l
.
strip
(),
locals
,
gl
)
#res = f(*args, **kwargs)
for k, v in kwargs.items():
print
(
"
%.3fs
\t
%.3fs
\t
%s
"
%
(
time
.
clock
()
-
tline
,
time
.
clock
()
-
tcum
,
l
.
strip
()))
if k not in tuple(arg_names) + (varargs, varkw):
w
=
wrap
kwargs.pop(k)
w
.
__name__
=
f
.
__name__
kwargs[varkw][k] = v
return
w
if defaults:
kwargs.update(dict(zip(arg_names[::-1], defaults[::-1])))
kwargs.update(dict(zip(arg_names, args)))
lines = inspect.getsourcelines(f)[0][2:]
tcum = time.clock()
locals = kwargs
gl = f.__globals__
for l in lines:
tline = time.clock()
exec(l.strip(), locals, gl) #res = f(*args, **kwargs)
print (
"
%
.
3
fs
\
t
%
.
3
fs
\
t
%
s
"
% (time.clock() - tline, time.clock() - tcum, l.strip()))
w = wrap
w.__name__ = f.__name__
return w
This diff is collapsed.
Click to expand it.
wetb/hawc2/htc_file.py
+
3
−
0
View file @
a5d4c0f6
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment