Speeed! [Two-Stage / GS Designs]
Hi Hötzi,
This is a funny way to do it. There will be constant memory re-allocation of the vector this way. I guess that's what takes the time.
Try and check if a technique called loop unrolling also helps speed things up in R. Sometimes it works miracles but is very implementation-specific. It has a little effect in my C implementations, but nothing really substantial so far.
The idea is (and pardon me for going from a for loop to a while loop; this is just because I don't know of a way to make a for loop increase by more than one per iteration, but I am sure you can do that):
In stead of
we can try
Here in stead of looping 10 times, we just need to loop 5 times. You can of course unroll a lot more than just x2 as the above example. One obvious drawback is that code can appear visually bloated but this of course doesn't affect functionality.
❝ for(j in seq_along(run)) v1 <- c(v1, rnorm(1, mean=0, sd=1))
This is a funny way to do it. There will be constant memory re-allocation of the vector this way. I guess that's what takes the time.
Try and check if a technique called loop unrolling also helps speed things up in R. Sometimes it works miracles but is very implementation-specific. It has a little effect in my C implementations, but nothing really substantial so far.
The idea is (and pardon me for going from a for loop to a while loop; this is just because I don't know of a way to make a for loop increase by more than one per iteration, but I am sure you can do that):
In stead of
i=0
while (i<10)
{
Do.Something(i)
i=i+1
}
we can try
i=0
while (i<10)
{
Do.Something(i)
Do.Something(i+1)
i=i+2
}
Here in stead of looping 10 times, we just need to loop 5 times. You can of course unroll a lot more than just x2 as the above example. One obvious drawback is that code can appear visually bloated but this of course doesn't affect functionality.
—
Pass or fail!
ElMaestro
Pass or fail!
ElMaestro
Complete thread:
- Gimmick & survey Helmut 2015-02-20 01:47
- Gimmick & survey nobody 2015-02-20 08:25
- Gimmick & survey Helmut 2015-02-20 13:01
- Gimmick & survey nobody 2015-02-20 14:18
- Speeed! Helmut 2015-02-20 15:38
- Speeed! nobody 2015-02-20 16:37
- Speeed!ElMaestro 2015-02-20 23:48
- Speeed! Helmut 2015-02-21 01:11
- Unrolled example ElMaestro 2015-02-21 01:32
- Unrolled example Helmut 2015-02-21 01:50
- Unrolled example ElMaestro 2015-02-21 02:27
- Increasing vector & another example Helmut 2015-02-21 13:13
- Unrolled example ElMaestro 2015-02-21 02:27
- Unrolled example Helmut 2015-02-21 01:50
- Speeed! nobody 2015-02-21 21:02
- Unrolled example ElMaestro 2015-02-21 01:32
- Speeed! Helmut 2015-02-21 01:11
- Speeed! Helmut 2015-02-20 15:38
- Gimmick & survey nobody 2015-02-20 14:18
- Gimmick & survey Helmut 2015-02-20 13:01
- Gimmick & survey nobody 2015-02-20 08:25