LoopThrottle.jl

Slow down Julia for loops and while loops to a desired maximum rate using a macro
Author tkoolen
Popularity
2 Stars
Updated Last
2 Years Ago
Started In
September 2017

LoopThrottle

Build Status codecov.io

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

x = 0
@throttle t for t = 1 : 0.01 : 2
    x += 1
end max_rate = 2.

will finish in approximately 0.5 second.

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.

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.

Required Packages

No packages found.