prawnpdf/pdf-core — pull request #8 by dsisnero (2014-09-18 18:03:35+00:00)
Title: Use frozen strings for performance

require 'benchmark'

n = 10_000_000

Benchmark.bm(14) do |x|

def render_header(output = [])
output << "%PDF-1.0\n"

# 4 binary chars, as recommended by the spec
output << "%\xFF\xFF\xFF\xFF\n"
end

def render_header_frozen(output = [])
output << "%PDF-1.0\n".freeze

# 4 binary chars, as recommended by the spec
output << "%\xFF\xFF\xFF\xFF\n".freeze
end

x.report("render"){
n.times do
render_header
end
}

x.report("render frozen"){
n.times do
render_header_frozen
end
}

end
------------------------------------

user system total real
render 3.588000 0.000000 3.588000 ( 3.600590)
render frozen 1.934000 0.000000 1.934000 ( 1.921306)