Created
June 6, 2012 18:55
-
-
Save vertexclique/2883896 to your computer and use it in GitHub Desktop.
Time Slice for Ruby methods (milliseconds)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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