Run a loop for a set amount of time

julia> function run(s)
           t = time()
           while time() < t + s
               sleep(0.001)
           end
       end
run (generic function with 1 method)

julia> @time run(0.1)
  0.101925 seconds (231 allocations: 6.766 KiB)

julia> @time run(0.5)
  0.502150 seconds (1.14 k allocations: 34.453 KiB)

julia> @time run(1.2)
  1.200282 seconds (2.75 k allocations: 83.469 KiB)

this is probably close to your tic toc in MATLAB

6 Likes