On 6/26/13 10:16 PM, Ben Goodrich wrote:
> On Wednesday, June 26, 2013 10:00:36 PM UTC-4, Mike Lawrence wrote:
>
> Ah! One big speedup can be achieved by not re-using variables inside the model block. I was initialized a variable,
> setting its value, then later re-setting its value to something else. On a hunch I tried initializing two variables
> and setting the value to each once, and this runs far faster.
>
>
> I would be surprised if something like that made any difference.
I think that depends on how bad the original program was :-)
For instance, this is slow:
vector[K] temp;
for (...) {
temp <- some calc for b;
... use temp ...
temp <- some calc for c;
... use temp ...
}
but this is faster:
vector[K] b;
b <- some calc for b;
vector[K] c;
c <- some calc for c;
for (...) {
... use b ...
... use c ...
}
There shouldn't be a noticeable difference between:
vector[K] temp;
temp <- some calc for b;
... use b ...
temp <- some calc for c;
... use c ...
and
vector[K] b;
b <- some calc for b;
vector[K] c;
c <- some calc for c;
... use b ...
... use c ...
In general, you want to define things that are used multiple
times as high up as possible.
- Bob