Skip to content

Instantly share code, notes, and snippets.

@qertoip
Created February 15, 2011 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qertoip/827529 to your computer and use it in GitHub Desktop.
Save qertoip/827529 to your computer and use it in GitHub Desktop.
Ruby 1.9.2-p136 String access bug
# -*- encoding : utf-8 -*-
require 'benchmark'
#s1 = "aaaaaaaaać" * 2_00
#
#puts Benchmark.measure() {
# for i in 0..2_000_000 do
# c = s1[i]
# end
#}
#
#exit( 0 )
require 'benchmark'
s1 = "ąćęłńóśżź!0123456789"
puts Benchmark.measure {
1000.times { k = s1[1] }
}
s2 = "ąćęłńóśżź!0123456789" * 100_000
puts Benchmark.measure {
1000.times { k = s2[1] }
}
exit( 0 )
s = "0123456789ąćęłńóśżź!" * 1_000_000 + "KONIEC"
puts s.size
puts s.bytesize
puts s.encoding
puts "index 1"
puts Benchmark.measure() {
1000.times { k = s[1] }
}
puts "index 1_000_000"
puts Benchmark.measure() {
1000.times { k = s[1_000_000] }
}
puts "index 2_000_000"
puts Benchmark.measure() {
1000.times { k = s[20_000_000] }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment