Skip to content

Instantly share code, notes, and snippets.

@directionless
Created October 10, 2012 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save directionless/3866649 to your computer and use it in GitHub Desktop.
Save directionless/3866649 to your computer and use it in GitHub Desktop.
cpu use test script
#!/usr/bin/env ruby
# we're seeing some odd slowdown on hosts. It kind of looks like the
# host is pausing for some number of milliseconds, which hits the
# various ruby processes. It would be nice if we understood what was
# happening. This is a small script to help understand it.
# theory:
# Do work that takes about N
# Measure elapsed time M
# whine if they differ my more than X
class Integer
def factors() (1..self).select { |n| (self % n).zero? } end
end
program_start = Time.now.to_f
while true
runtime = Time.now.to_f - program_start
#puts "Total runtime: #{runtime}"
start = Time.new.to_f
# Do some work. Looking for factors is work.
# this set of math was arrived at somewhat experimentally.
(100000 + rand(99999)).factors
(100000 + rand(99999)).factors
elapsed = Time.new.to_f - start
puts elapsed
whine_time = 0.500
if elapsed > whine_time
puts "uh oh"
puts "This round took took #{elapsed}"
exit
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment