Skip to content

Instantly share code, notes, and snippets.

@kennethkalmer
Created December 13, 2012 23:21
Show Gist options
  • Save kennethkalmer/4281051 to your computer and use it in GitHub Desktop.
Save kennethkalmer/4281051 to your computer and use it in GitHub Desktop.
require 'prawn'
require 'benchmark'
pdf = Prawn::Document.new
cell = Prawn::Table::Cell.make( pdf, "Some text" )
n = 100_000
Benchmark.bm do |x|
x.report("cached") { n.times { cell.send(:styled_width_of_single_character) } }
x.report("direct") { n.times { cell.send(:styled_width_of, "M") } }
end
jruby 1.7.0 (1.9.3p203) 2012-10-22 ff1ebbe on Java HotSpot(TM) 64-Bit Server VM 1.7.0_09-b05 [darwin-x86_64]
user system total real
cached 3.140000 0.050000 3.190000 ( 1.293000)
direct 1.220000 0.030000 1.250000 ( 0.677000)
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]
user system total real
cached 0.900000 0.000000 0.900000 ( 0.909466)
direct 1.110000 0.000000 1.110000 ( 1.102518)
@yob
Copy link

yob commented Dec 15, 2012

The results on my system are similar in proportion. for MRI 1.9 the caching provides a larger benefit.

Maybe thread local vars are expensive on jruby?

ruby 1.9.3p327 (2012-11-10) [x86_64-linux]

   user     system      total        real
cached  0.470000   0.000000   0.470000 (  0.475054)
direct  0.830000   0.000000   0.830000 (  0.832003)

jruby 1.7.1 (1.9.3p327) 2012-12-03 30a153b on OpenJDK 64-Bit Server VM 1.7.0_03-b21 [linux-amd64]

   user     system      total        real
cached  3.980000   0.050000   4.030000 (  2.439000)
direct  1.710000   0.010000   1.720000 (  1.242000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment