# Run a loop for a set amount of time

**URL:** https://discourse.julialang.org/t/run-a-loop-for-a-set-amount-of-time/82026
**Category:** New to Julia
**Tags:** question
**Created:** [June 1, 2022, 3:13am UTC](https://discourse.julialang.org/t/run-a-loop-for-a-set-amount-of-time/82026 "2022-06-01T03:13:19Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [June 1, 2022, 6:42pm UTC](https://discourse.julialang.org/t/run-a-loop-for-a-set-amount-of-time/82026/5 "2022-06-01T18:42:47Z")

</div>

> [@Is it necessary for sleep to allocate?](https://discourse.julialang.org/t/is-it-necessary-for-sleep-to-allocate/77795):
>
> I was optimizing a complex block of multithreaded code and discovered that sleep was allocating. julia\> @btime sleep(0) 1.720 μs (5 allocations: 144 bytes) I was pretty surprised, so checked the [source](https://github.com/JuliaLang/julia/blob/2ba3a22858938ecaf41bbe3e780df507556825c5/base/asyncevent.jl#L232) which is basically wait(Timer(sec)), so it’s allocating a mutable struct for that Timer. Is there a more efficient alternative to that to sleep for a very short time? I found a [reference to usleep](https://discourse.julialang.org/t/accuracy-of-sleep/5546/3) but I’m on Windows so that’s not an option for me. I need a thread to sleep briefly (millisecon…

---

_[View the full topic](https://discourse.julialang.org/t/run-a-loop-for-a-set-amount-of-time/82026)._
