Skip to content

Instantly share code, notes, and snippets.

@foxweb
Last active August 29, 2015 14:01
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 foxweb/077614da940aa84050ec to your computer and use it in GitHub Desktop.
Save foxweb/077614da940aa84050ec to your computer and use it in GitHub Desktop.
require 'benchmark'
n = 10000000000
Benchmark.bm do |x|
x.report { puts "hello йё".force_encoding("ISO-8859-1").encode("UTF-8") } # насильно в латиницу и обратно в UTF
x.report { puts "hello йё".encode("UTF-8").force_encoding('UTF-8') } # из UTF и в UTF
x.report { puts "hello йё".encode("UTF-8", invalid: :replace, undef: :replace, replace: "?") } # мягкое исправление ошибок кодировки
x.report { puts "hello йё" } # как есть
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment