In [10]:
import glob
import pysd
documentation on how to sort the profile output is here: https://docs.python.org/2/library/profile.html#pstats.Stats.sort_stats
In [12]:
# load model files from system zoo:
# http://www.usf.uni-kassel.de/cesr/index.php?option=com_remository&Itemid=141&func=fileinfo&id=109
mdl_files = glob.glob('vensim/ZOO MDL/*/*/*/*.mdl')
len(mdl_files)
Out[12]:
In [16]:
for mdl_file in mdl_files:
print mdl_file
try:
model = pysd.read_vensim(mdl_file)
try:
model.run()
except:
print 'fail run'
except:
print 'fail import'
In [6]:
%load_ext line_profiler
#import line_profiler as lp
In [4]:
import pysd
model = pysd.read_vensim('vensim/Teacup.mdl')
In [15]:
from pysd.translators import import_vensim
%lprun import_vensim('vensim/Teacup.mdl')
In [16]:
%lprun pysd.read_vensim('vensim/Teacup.mdl')
In [7]:
%prun model = pysd.read_vensim('vensim/Teacup.mdl')
In [26]:
%lprun -v model.run()
In [17]:
# look here http://ipython.org/ipython-doc/2/api/generated/IPython.core.magics.execution.html
%prun -s cumulative model.run()
In [18]:
# look here http://ipython.org/ipython-doc/2/api/generated/IPython.core.magics.execution.html
%prun -s time model.run()
In [20]:
import timeit
hi = 19
timeit.timeit('hi*3')
In [22]:
from timeit import Timer
t = Timer(lambda: pysd.read_vensim('vensim/Teacup.mdl'))
print t.timeit(number=1)
In [32]:
import pstats, cProfile
import pysd
model = pysd.read_vensim('vensim/Teacup.mdl')
#cProfile.run(pysd.read_vensim('vensim/Teacup.mdl'), 'prof_import.prof')
cProfile.runctx("model.run()", globals(), locals(), "prof_import.prof")
#s = pstats.Stats("Profile.prof")
#s.strip_dirs().sort_stats("time").print_stats()
In [35]:
! cprofilev -f prof_import.prof
In [11]:
python -m cprofilev profile_pysd.py
In [23]:
from itertools import izip
keys = range(100)
values = range(100)
%timeit dict(zip(keys,values))
In [24]:
%timeit dict(izip(keys,values))
In [37]:
def hi():
return 'hi'
def there():
return 'there'
funclist = []
funclist.append(hi)
funclist.append(there)
In [38]:
[f() for f in funclist]
Out[38]:
In [42]:
l = ['a']
l.index('a')
Out[42]:
In [45]:
l2 = []
l2.insert(0, 'hi')
In [44]:
l3 = [1, 2]
l3.insert(0'hi',0)
In [40]:
index = funclist.index('chewie')
In [41]:
model.components._stocknames
Out[41]:
In [47]:
model.run()
Out[47]:
In [ ]: