Created
January 6, 2013 08:26
-
-
Save kennethkalmer/4466065 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' | |
LIPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam urna | |
augue, tempor a ornare tempor, blandit in sapien. Cras et purus sit amet eros | |
dictum euismod non sed risus. Duis sed commodo felis. Fusce scelerisque | |
gravida nunc, nec malesuada elit volutpat eu. Mauris rutrum posuere hendrerit. | |
Nulla laoreet semper tristique. Nullam aliquam dignissim auctor. Sed luctus | |
posuere ultricies. Proin felis lacus, feugiat eu aliquam vitae, fringilla | |
molestie quam." | |
# Add text and tables of Lipsum with an AFM & TTF font | |
def basic_pdf | |
pdf = Prawn::Document.new | |
pdf.font 'Helvetica' | |
pdf.text LIPSUM | |
pdf.table([[ LIPSUM, LIPSUM ]]) | |
pdf.font File.join( Prawn::DATADIR, 'fonts', 'Chalkboard.ttf' ) | |
pdf.text LIPSUM | |
pdf.table([[ LIPSUM, LIPSUM ]]) | |
pdf.render | |
#$stdout.write "." | |
end | |
def bigger_pdf | |
end | |
n = 100 | |
Benchmark.bm do |x| | |
x.report("basic_pdf") { n.times { basic_pdf } } | |
#x.report("bigger_pdf") { n.times { bigger_pdf } } | |
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
Benchmarks at present with MRI 1.9.3-p327 on Mountain Lion | |
Master (with memory leak) | |
user system total real | |
basic_pdf 18.590000 0.050000 18.640000 ( 18.643244) | |
------------------------------------------------------ | |
table-memory-leak (without cache) | |
user system total real | |
basic_pdf 18.890000 0.030000 18.920000 ( 18.929270) | |
------------------------------------------------------ | |
table-memory-leak (with naive metric cache) | |
user system total real | |
basic_pdf 14.820000 0.030000 14.850000 ( 14.857459) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment