Skip to content

Instantly share code, notes, and snippets.

@adrianpike
Created November 1, 2010 22:39
Show Gist options
  • Save adrianpike/659005 to your computer and use it in GitHub Desktop.
Save adrianpike/659005 to your computer and use it in GitHub Desktop.
Cadence measuring with the rubies
SAMPLE_SIZE = 100 # set this
i = 0
matches = {}
old = " "
while i < SAMPLE_SIZE
begin
system("stty raw -echo")
t1 = Time.now.to_f
str = STDIN.getc
t2 = Time.now.to_f
ensure
system("stty -raw echo")
end
printf str.chr
time = (t2-t1).to_s
matches[old+' '+str.chr] = [] unless matches[old+' '+str.chr]
matches[old+' '+str.chr] << time
old = str.chr
i+=1
end
printf "\n\n\n"
matches.keys.each{|k|
val = matches[k].inject{ |sum, el| sum.to_f + el.to_f }.to_f / matches[k].size
puts "#{k} : #{val.to_s} (#{matches[k].size})"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment