Skip to content

Instantly share code, notes, and snippets.

@nkokkos
Created June 28, 2023 10:51
Show Gist options
  • Save nkokkos/a320a0bbcb47ce7e77f621d55c1a9528 to your computer and use it in GitHub Desktop.
Save nkokkos/a320a0bbcb47ce7e77f621d55c1a9528 to your computer and use it in GitHub Desktop.
require './ring_buffer.rb'
iterations = 1000
RING_SIZE = 25
ring = RingBuffer.new(RING_SIZE)
iterations.times do |i|
time_start = Time.now
400000.times do |t|
[t, Math.sqrt(rand(200000)), Math.sqrt(t)**2]
end
time_now = Time.now
time_taken = time_now - time_start
ring << time_taken
puts "time taken for compute block: #{time_taken}"
if ring.full?
#https://stackoverflow.com/questions/1341271/how-do-i-create-an-average-from-a-ruby-array
moving_average = ring.buffer.inject{ |sum, el| sum + el }.to_f / RING_SIZE
time_left = moving_average * (iterations - i)
puts "time_left: #{time_left}, minutes: #{(time_left/60.0).round(2)}"
puts "--------------------------------------"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment