-
I tested exported model is a lot faster than modelx. I wondered the speed difference between exported model and code without modelx. So.. I put very simple code without modelx. It consists of 3 functions and 1,000,000 model points(csv) and one lapse assumption table(csv). and I coded the same variables, table in modelx and exported them. Pickled table.. and functions are exactly same. My guess was exported model would be slower than code without modelx since it has many features anyway. but result was surprising. Exported model is much faster than code without modelx (almost 20 times!) How it is possible? What is the mechanism that makes exported model much faster? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
That's because the exported model uses caching (a.k.a. memoization) mechanism. For example, when |
Beta Was this translation helpful? Give feedback.
That's because the exported model uses caching (a.k.a. memoization) mechanism. For example, when
foo(100)
is called for the first time in the exported model, the returned value offoo(100)
is remembered. Then, whenfoo(100)
is called the next time, the saved value is returned. In the pure-Python model,foo(100)
is calculated every time it's called. You can achieve a similar effect by writing functions with @cache from the functools standard library.