Skip to content

Instantly share code, notes, and snippets.

@seak0503
Created April 3, 2015 08:15
Show Gist options
  • Save seak0503/6060726a6e05a60d7168 to your computer and use it in GitHub Desktop.
Save seak0503/6060726a6e05a60d7168 to your computer and use it in GitHub Desktop.
文字列、数値、シンボルのベンチマーク比較
require "benchmark"
str_time = Benchmark.realtime do
10000000.times { "abcde" == "abcde" }
end
int_time = Benchmark.realtime do
10000000.times { 12345 == 12345 }
end
sym_time = Benchmark.realtime do
10000000.times { :abcde == :abcde }
end
puts("文字列の場合の処理時間: #{str_time}")
puts("数値型の場合の処理時間: #{int_time}")
puts("シンボルの場合の処理時間: #{sym_time}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment