Skip to content

Instantly share code, notes, and snippets.

@ecasilla
Created January 3, 2014 22:05
Show Gist options
  • Save ecasilla/8247545 to your computer and use it in GitHub Desktop.
Save ecasilla/8247545 to your computer and use it in GitHub Desktop.
Processors
# The first term is the speed of light in meters per second
# (this is actually exact - a meter is defined as
# "the length of the path travelled by light in vacuum during a time interval of 1/299 792 458 of a second.".
# The second term, 100 is the number of centimeters in a meter.
# The third term, 1.0/1000000000 is one billionth. (Note that we need the .0 here (or at least 1.)
# to make Ruby do floating point division. Otherwise, 1/1000000000 would evaluate to 0.)
# So, the first three terms in the product compute the distance in centimeters
# that light travels in one billionth of a second (or one nanosecond).
# To compute the number of nanoseconds per cycle for my 1.8 GHz processor,
# the fourth term is 1 / 1.8. Since there are 1.8 Billion cycles per second,
# there are 1.8 cycles per nanosecond, and each cycle takes 1 / 1.8 nanoseconds.
# The method calculate_cycle calculates your own computer ghz if your go to mac
# Apple logo on your nav bar you can see your processor speed
# Then you can calcualte the percentage of a nanosecond that your
# computer takes to compelete a single cycle
def calculate_cycle(ghz)
299792458 * 100 * 1.0/1000000000 * 1/ghz
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment