Created
December 13, 2012 23:21
-
-
Save kennethkalmer/4281051 to your computer and use it in GitHub Desktop.
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
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 |
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
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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]
jruby 1.7.1 (1.9.3p327) 2012-12-03 30a153b on OpenJDK 64-Bit Server VM 1.7.0_03-b21 [linux-amd64]