https://github.com/tkoolen/loopthrottle.jl
Slow down Julia for loops and while loops to a desired maximum rate using a macro
https://github.com/tkoolen/loopthrottle.jl
Last synced: about 2 months ago
JSON representation
Slow down Julia for loops and while loops to a desired maximum rate using a macro
- Host: GitHub
- URL: https://github.com/tkoolen/loopthrottle.jl
- Owner: tkoolen
- License: other
- Created: 2017-09-29T01:03:26.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-02-12T13:31:30.000Z (about 5 years ago)
- Last Synced: 2025-02-23T04:20:26.362Z (2 months ago)
- Language: Julia
- Homepage:
- Size: 18.6 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# LoopThrottle
[](https://travis-ci.org/tkoolen/LoopThrottle.jl)
[](http://codecov.io/github/tkoolen/LoopThrottle.jl?branch=master)LoopThrottle is a tiny Julia package that exports the `@throttle` macro, which can be used to
slow down a `for` loop or `while` loop by calling `sleep` at the beginning of each
loop iteration (if necessary), so that a designated variable increases
at a rate of at most `max_rate` (compared to wall time).## Examples
```julia
x = 0
@throttle t for t = 1 : 0.01 : 2
x += 1
end max_rate = 2.
```
will finish in approximately 0.5 second.```julia
x = 0.
@throttle x for i = 0 : 1000
x += 1e-3
end
```
will use the default `max_rate` value of `1.` and thus finish in approximately 1 second.
```julia
i = 0
@throttle i while i <= 10
println(i)
i += 1
end min_sleep_time=1.5 max_rate=1
```
will print the numbers from 0 to 10 at an average rate of one per second, while never
sleeping for less than 1.5 second.