Skip to content

Instantly share code, notes, and snippets.

@vertexclique
Created June 6, 2012 18:55
Show Gist options
  • Save vertexclique/2883896 to your computer and use it in GitHub Desktop.
Save vertexclique/2883896 to your computer and use it in GitHub Desktop.
Time Slice for Ruby methods (milliseconds)
module TimeSlice
def self.time_slice(slice)
bgntime = Time.now
id = 0
loop do
id=id+1
puts "#{id} works"
# do your work here like above line
# and pass milliseconds for "slice" var
endtime = Time.now
if (((endtime - bgntime)*1000) > Integer(slice))
break
end
end
puts "Time slice ended"
end
end
# 5000 milliseconds time slice
TimeSlice.time_slice(5000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment