Permalink
Browse files

The beginning of the core benchmarks

  • Loading branch information...
Evan Phoenix
Evan Phoenix committed Feb 8, 2010
1 parent 73a583d commit ce306b0bf42d3330dbabdf750580bbe9aa7ea7d0
Showing with 1,150 additions and 0 deletions.
  1. +78 −0 benchmark/core/compare.rb
  2. +41 −0 benchmark/core/cps.rb
  3. +48 −0 benchmark/core/generate.rb
  4. +10 −0 benchmark/core/methods/string/append_op.rb
  5. +10 −0 benchmark/core/methods/string/aref_op.rb
  6. +10 −0 benchmark/core/methods/string/aref_op_length.rb
  7. +11 −0 benchmark/core/methods/string/aref_op_range.rb
  8. +10 −0 benchmark/core/methods/string/aref_op_regex.rb
  9. +10 −0 benchmark/core/methods/string/aref_op_string.rb
  10. +10 −0 benchmark/core/methods/string/aset_op.rb
  11. +10 −0 benchmark/core/methods/string/bytes.rb
  12. +10 −0 benchmark/core/methods/string/bytesize.rb
  13. +10 −0 benchmark/core/methods/string/capitalize.rb
  14. +10 −0 benchmark/core/methods/string/capitalize_bang.rb
  15. +10 −0 benchmark/core/methods/string/casecmp.rb
  16. +10 −0 benchmark/core/methods/string/center.rb
  17. +10 −0 benchmark/core/methods/string/chars.rb
  18. +10 −0 benchmark/core/methods/string/chomp.rb
  19. +10 −0 benchmark/core/methods/string/chomp_bang.rb
  20. +10 −0 benchmark/core/methods/string/chop.rb
  21. +10 −0 benchmark/core/methods/string/chop_bang.rb
  22. +12 −0 benchmark/core/methods/string/compare_op.rb
  23. +10 −0 benchmark/core/methods/string/concat.rb
  24. +10 −0 benchmark/core/methods/string/count.rb
  25. +12 −0 benchmark/core/methods/string/crypt.rb
  26. +10 −0 benchmark/core/methods/string/delete.rb
  27. +10 −0 benchmark/core/methods/string/delete_bang.rb
  28. +10 −0 benchmark/core/methods/string/downcase.rb
  29. +10 −0 benchmark/core/methods/string/downcase_bang.rb
  30. +10 −0 benchmark/core/methods/string/dump.rb
  31. +10 −0 benchmark/core/methods/string/each.rb
  32. +10 −0 benchmark/core/methods/string/each_byte.rb
  33. +10 −0 benchmark/core/methods/string/each_char.rb
  34. +10 −0 benchmark/core/methods/string/each_line.rb
  35. +10 −0 benchmark/core/methods/string/empty_eh.rb
  36. +10 −0 benchmark/core/methods/string/end_with_eh.rb
  37. +10 −0 benchmark/core/methods/string/eql_eh.rb
  38. +10 −0 benchmark/core/methods/string/equal_op.rb
  39. +10 −0 benchmark/core/methods/string/gsub.rb
  40. +10 −0 benchmark/core/methods/string/gsub_bang.rb
  41. +10 −0 benchmark/core/methods/string/hash.rb
  42. +9 −0 benchmark/core/methods/string/helpers.rb
  43. +10 −0 benchmark/core/methods/string/hex.rb
  44. +10 −0 benchmark/core/methods/string/include_eh.rb
  45. +10 −0 benchmark/core/methods/string/index.rb
  46. +10 −0 benchmark/core/methods/string/insert.rb
  47. +10 −0 benchmark/core/methods/string/inspect.rb
  48. +10 −0 benchmark/core/methods/string/intern.rb
  49. +10 −0 benchmark/core/methods/string/length.rb
  50. +10 −0 benchmark/core/methods/string/lines.rb
  51. +10 −0 benchmark/core/methods/string/ljust.rb
  52. +10 −0 benchmark/core/methods/string/lstrip.rb
  53. +10 −0 benchmark/core/methods/string/lstrip_bang.rb
  54. +10 −0 benchmark/core/methods/string/match.rb
  55. +10 −0 benchmark/core/methods/string/modulo_op.rb
  56. +10 −0 benchmark/core/methods/string/next.rb
  57. +10 −0 benchmark/core/methods/string/next_bang.rb
  58. +10 −0 benchmark/core/methods/string/oct.rb
  59. +10 −0 benchmark/core/methods/string/partition.rb
  60. +10 −0 benchmark/core/methods/string/plus_op.rb
  61. +10 −0 benchmark/core/methods/string/regex_equal_op.rb
  62. +10 −0 benchmark/core/methods/string/replace.rb
  63. +10 −0 benchmark/core/methods/string/reverse.rb
  64. +10 −0 benchmark/core/methods/string/reverse_bang.rb
  65. +10 −0 benchmark/core/methods/string/rindex.rb
  66. +10 −0 benchmark/core/methods/string/rjust.rb
  67. +10 −0 benchmark/core/methods/string/rpartition.rb
  68. +10 −0 benchmark/core/methods/string/rstrip.rb
  69. +10 −0 benchmark/core/methods/string/rstrip_bang.rb
  70. +10 −0 benchmark/core/methods/string/scan.rb
  71. +10 −0 benchmark/core/methods/string/size.rb
  72. +10 −0 benchmark/core/methods/string/slice.rb
  73. +10 −0 benchmark/core/methods/string/slice_bang.rb
  74. +10 −0 benchmark/core/methods/string/split.rb
  75. +10 −0 benchmark/core/methods/string/squeeze.rb
  76. +10 −0 benchmark/core/methods/string/squeeze_bang.rb
  77. +10 −0 benchmark/core/methods/string/start_with_eh.rb
  78. +10 −0 benchmark/core/methods/string/strip.rb
  79. +10 −0 benchmark/core/methods/string/strip_bang.rb
  80. +10 −0 benchmark/core/methods/string/sub.rb
  81. +10 −0 benchmark/core/methods/string/sub_bang.rb
  82. +10 −0 benchmark/core/methods/string/succ.rb
  83. +10 −0 benchmark/core/methods/string/succ_bang.rb
  84. +10 −0 benchmark/core/methods/string/sum.rb
  85. +10 −0 benchmark/core/methods/string/swapcase.rb
  86. +10 −0 benchmark/core/methods/string/swapcase_bang.rb
  87. +10 −0 benchmark/core/methods/string/times_op.rb
  88. +10 −0 benchmark/core/methods/string/to_f.rb
  89. +10 −0 benchmark/core/methods/string/to_i.rb
  90. +10 −0 benchmark/core/methods/string/to_s.rb
  91. +10 −0 benchmark/core/methods/string/to_str.rb
  92. +10 −0 benchmark/core/methods/string/to_sym.rb
  93. +10 −0 benchmark/core/methods/string/tr.rb
  94. +10 −0 benchmark/core/methods/string/tr_bang.rb
  95. +10 −0 benchmark/core/methods/string/tr_s.rb
  96. +10 −0 benchmark/core/methods/string/tr_s_bang.rb
  97. +10 −0 benchmark/core/methods/string/unpack.rb
  98. +10 −0 benchmark/core/methods/string/upcase.rb
  99. +10 −0 benchmark/core/methods/string/upcase_bang.rb
  100. +10 −0 benchmark/core/methods/string/upto.rb
  101. +9 −0 benchmark/core/null.rb
View
@@ -0,0 +1,78 @@
def results(what, file)
str = `#{what} ./cps.rb #{file}`
raise "Unable to execute #{what} on #{file}" unless str
begin
Integer(str.split("\n").last.split(" : ").last)
rescue
puts "ERROR"
puts str
return 0
end
end
def compare(name, base, int)
base_ips = Integer(base)
int_ips = Integer(int)
times_fast = "%.3f" % (int_ips.to_f / base_ips)
puts "%10s %6sx #{int_ips}" % [name, times_fast]
end
def compute_files(arg)
return [arg] if File.file?(arg)
if arg.index(":")
if arg.index("/")
files = Dir["methods/#{arg[1..-1]}*.rb"]
else
files = Dir["methods/#{arg[1..-1]}/*.rb"]
end
elsif File.directory?(arg)
files = Dir["#{arg}/*.rb"]
else
files = Dir[arg].reject { |i| !/\.rb$/.match(i) }
end
files.reject do |i|
File.basename(i) == "helpers.rb" or File.read(i).index("not implemented") != nil
end
end
def expand_int(int)
case int
when ":rbx"
return "../../bin/rbx"
else
return int
end
end
files = compute_files(ARGV.shift).sort
baseline_name = ARGV.shift
baseline_total = 0
totals = Hash.new { |h,k| h[k] = 0 }
files.each do |file|
puts file
baseline = results(baseline_name, file)
baseline_total += baseline
compare(baseline_name, baseline, baseline)
ARGV.each do |int|
int = expand_int(int)
res = results(int, file)
totals[int] += res
compare(File.basename(int), baseline, res)
end
end
puts "\nTOTAL:"
ARGV.each do |int|
int = expand_int(int)
res = totals[int]
compare(File.basename(int), baseline_total, res)
end
View
@@ -0,0 +1,41 @@
module Bench
def self.start_timer(time=5)
@should_run = true
Thread.new(time) do |t|
sleep t
@should_run = false
end
end
def self.perform(time)
t = start_timer(time)
before = Time.now
run
fin = Time.now
t.join
diff = fin - before
printf "%.1f : %d : %d\n" % [diff, @iterations, (@iterations / diff).round]
end
end
file = ARGV.shift
helpers = File.join(File.dirname(file), "helpers.rb")
p helpers
if File.exists? helpers
load helpers
end
load file
Bench.perform(1)
Bench.perform(1)
Bench.perform(1)
Bench.perform(5)
View
@@ -0,0 +1,48 @@
klass = eval("#{ARGV.shift}")
klass_name = klass.to_s.downcase
map = {
"%" => "modulo_op",
"*" => "times_op",
"+" => "plus_op",
"<<" => "append_op",
"<=>" => "compare_op",
"==" => "equal_op",
"=~" => "regex_equal_op",
"[]" => "aref_op",
"[]=" => "aset_op"
}
unless File.directory?("methods/#{klass_name}")
Dir.mkdir("methods/#{klass_name}")
end
klass.instance_methods(false).each do |meth|
if sub = map[meth]
meth = sub
end
meth.sub!(/\!$/, "_bang")
meth.sub!(/\?$/, "_eh")
file = "methods/#{klass_name}/#{meth}.rb"
unless File.exists?(file)
puts file
File.open(file, "w") do |f|
f << <<-CODE
def Bench.run
i = 0
while @should_run
# #{klass_name}##{meth}(...)
raise "#{klass_name}##{meth}(...) benchmark is not implemented"
i += 1
end
@iterations = i
end
CODE
end
end
end
@@ -0,0 +1,10 @@
def Bench.run
i = 0
s = "hello"
while @should_run
s.dup << " world"
i += 1
end
@iterations = i
end
@@ -0,0 +1,10 @@
def Bench.run
i = 0
str = "blah"
while @should_run
str[0]
i += 1
end
@iterations = i
end
@@ -0,0 +1,10 @@
def Bench.run
i = 0
str = "blah"
while @should_run
str[0,2]
i += 1
end
@iterations = i
end
@@ -0,0 +1,11 @@
def Bench.run
i = 0
str = "blah"
range = 0..2
while @should_run
str[range]
i += 1
end
@iterations = i
end
@@ -0,0 +1,10 @@
def Bench.run
i = 0
str = "blah"
while @should_run
str[/la/]
i += 1
end
@iterations = i
end
@@ -0,0 +1,10 @@
def Bench.run
i = 0
str = "blah"
while @should_run
str["la"]
i += 1
end
@iterations = i
end
@@ -0,0 +1,10 @@
def Bench.run
i = 0
while @should_run
# string#aset_op(...)
raise "string#aset_op(...) benchmark is not implemented"
i += 1
end
@iterations = i
end
@@ -0,0 +1,10 @@
def Bench.run
i = 0
while @should_run
# string#bytes(...)
raise "string#bytes(...) benchmark is not implemented"
i += 1
end
@iterations = i
end
@@ -0,0 +1,10 @@
def Bench.run
i = 0
while @should_run
# string#bytesize(...)
raise "string#bytesize(...) benchmark is not implemented"
i += 1
end
@iterations = i
end
@@ -0,0 +1,10 @@
def Bench.run
i = 0
str = random_string()
while @should_run
str.capitalize
i += 1
end
@iterations = i
end
@@ -0,0 +1,10 @@
def Bench.run
i = 0
while @should_run
# string#capitalize_bang(...)
raise "string#capitalize_bang(...) benchmark is not implemented"
i += 1
end
@iterations = i
end
@@ -0,0 +1,10 @@
def Bench.run
i = 0
str = "hello"
while @should_run
str.casecmp("Hello")
i += 1
end
@iterations = i
end
@@ -0,0 +1,10 @@
def Bench.run
i = 0
str = "hello"
while @should_run
str.center(20)
i += 1
end
@iterations = i
end
@@ -0,0 +1,10 @@
def Bench.run
i = 0
while @should_run
# string#chars(...)
raise "string#chars(...) benchmark is not implemented"
i += 1
end
@iterations = i
end
@@ -0,0 +1,10 @@
def Bench.run
i = 0
str = "hello\n\n"
while @should_run
str.chomp
i += 1
end
@iterations = i
end
@@ -0,0 +1,10 @@
def Bench.run
i = 0
while @should_run
# string#chomp_bang(...)
raise "string#chomp_bang(...) benchmark is not implemented"
i += 1
end
@iterations = i
end
@@ -0,0 +1,10 @@
def Bench.run
i = 0
str = "hello"
while @should_run
str.chop
i += 1
end
@iterations = i
end
@@ -0,0 +1,10 @@
def Bench.run
i = 0
while @should_run
# string#chop_bang(...)
raise "string#chop_bang(...) benchmark is not implemented"
i += 1
end
@iterations = i
end
@@ -0,0 +1,12 @@
def Bench.run
i = 0
str1 = random_string()
str2 = random_string()
while @should_run
str1 <=> str2
i += 1
end
@iterations = i
end
@@ -0,0 +1,10 @@
def Bench.run
i = 0
while @should_run
# string#concat(...)
raise "string#concat(...) benchmark is not implemented"
i += 1
end
@iterations = i
end
Oops, something went wrong.

0 comments on commit ce306b0

Please sign in to comment.