How could I speed up the following while loop?
count <- function(start, stepsize, threshold) {
i <- 1;
while ( start <= threshold ) {
start <- stepsize*i+start;
i <- i+1;
}
return( i-1 );
}
system.time(count(1, 0.004, 1e10))
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Working out the sums as in the comment above:
A function to solve this quadratic equation:
This solution takes essentially no time …
The question is whether this generalizes to the exact problem you need to solve.