Stop a loop if it takes long time

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Stop a loop if it takes long time

Bogaso
Hi,

Let say I am implementing a loop using for() / apply()-family etc.

Now, the calculation-time within a particular loop is not fixed, means,
some loop takes a long time to finish calculation, and next loop perhaps
very quick to finish.

I am exploring if there is any way, to check if the calculation within a
particular loop takes longer time than a pre-fixed threshold and if it does
then kill that loop and proceed to the next.

Is it possible to implement such without adding much overhead with existing
calculation?

Thanks for your feedback

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Stop a loop if it takes long time

Jeff Newmiller
Depends somewhat on what you are doing in the loop and how much of a performance hit you are willing to accept. [1]

[1] https://stackoverflow.com/questions/7891073/time-out-an-r-command-via-something-like-try

On July 24, 2018 3:17:41 AM PDT, Christofer Bogaso <[hidden email]> wrote:

>Hi,
>
>Let say I am implementing a loop using for() / apply()-family etc.
>
>Now, the calculation-time within a particular loop is not fixed, means,
>some loop takes a long time to finish calculation, and next loop
>perhaps
>very quick to finish.
>
>I am exploring if there is any way, to check if the calculation within
>a
>particular loop takes longer time than a pre-fixed threshold and if it
>does
>then kill that loop and proceed to the next.
>
>Is it possible to implement such without adding much overhead with
>existing
>calculation?
>
>Thanks for your feedback
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>[hidden email] mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.