Skip to content

Commit

Permalink
Merge pull request #2831 from kwleland/string_element_assignment
Browse files Browse the repository at this point in the history
String[]= benchmark added
  • Loading branch information
chuckremes committed Dec 17, 2013
2 parents f2dc601 + 178467c commit 4b35716
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions benchmark/core/string/bench_element_assignment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'benchmark'
require 'benchmark/ips'

Benchmark.ips do |x|

s = "abcdefghijk"
last_index = s.length - 1
middle_index = last_index/2

x.report("element assignment at beginning") do |times|
i = 0
while i < times
s[0] = "x"
i += 1
end
end

x.report("element assignment in middle") do |times|
i = 0
while i < times
s[middle_index] = "x"
i += 1
end
end

x.report("element assignment at end") do |times|
i = 0
while i < times
s[last_index] = "x"
i += 1
end
end

end
2 changes: 1 addition & 1 deletion benchmark/core/string/bench_scan.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'benchmark'
require 'benchmark/ips'

long_file = File.join(File.dirname(__FILE__), 'large.txt')
long_file = File.join("..","file",'large.txt')
long_text = File.new(long_file).read.downcase
medium_text = long_text.slice(0,1000)
short_text = long_text.slice(0,100)
Expand Down

0 comments on commit 4b35716

Please sign in to comment.