Created
January 7, 2012 03:30
-
-
Save bradland/1573685 to your computer and use it in GitHub Desktop.
Encoding benchmarks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# bench_encoding.rb | |
#!/usr/bin/env ruby -wKU | |
# encoding: UTF-8 | |
require 'benchmark' | |
p "Encoding is currently: #{__ENCODING__}" | |
report_width = 32 | |
Benchmark.bm(report_width) do|b| | |
b.report("UTF-8 to LATIN-1") do | |
1_000_000.times do |file| | |
str = "Señor Brad is in da house! Señor Brad is in da house! Señor Brad is in da house! Señor Brad is in da house! Señor Brad is in da house! Señor Brad is in da house! Señor Brad is in da house! Señor Brad is in da house! Señor Brad is in da house! Señor Brad is in da house!" | |
str.force_encoding("ISO-8859-1") | |
end | |
end | |
end | |
Benchmark.bm(report_width) do|b| | |
b.report("String assignment only") do | |
1_000_000.times do |file| | |
str = "Señor Brad is in da house! Señor Brad is in da house! Señor Brad is in da house! Señor Brad is in da house! Señor Brad is in da house! Señor Brad is in da house! Señor Brad is in da house! Señor Brad is in da house! Señor Brad is in da house! Señor Brad is in da house!" | |
end | |
end | |
end | |
# Results | |
"Encoding is currently: UTF-8" | |
user system total real | |
UTF-8 to LATIN-1 0.500000 0.000000 0.500000 ( 0.509272) | |
user system total real | |
String assignment only 0.180000 0.000000 0.180000 ( 0.177283) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment