Created
June 1, 2011 20:32
-
-
Save seeflanigan/1003239 to your computer and use it in GitHub Desktop.
Prawn vs PDFKit Benchmark
This file contains hidden or 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
-> % ./prawn_vs_pdfkit.rb | |
user system total real | |
PDFKit: 1.760000 1.850000 231.550000 (286.579597) | |
Prawn: 99.140000 0.890000 100.030000 (102.124293) | |
2.4 GHz Intel Core 2 Duo | |
4 GB 1067 MHz DDR3 |
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'benchmark' | |
require 'faker' | |
require 'pdfkit' | |
require 'prawn' | |
LINES = (ENV["LINES"] ? ENV["LINES"].to_i : 300) | |
TIMES = (ENV["TIMES"] ? ENV["TIMES"].to_i : 100) | |
WIDTH = (ENV["WIDTH"] ? ENV["WIDTH"].to_i : 10) | |
LOREM = Faker::Lorem.paragraph(LINES) | |
def do_pdfkit | |
doc = PDFKit.new(LOREM) | |
doc.to_file('/tmp/prawn_vs_pdfkit/benchmark_pdfkit.pdf') | |
end | |
def do_prawn | |
doc = Prawn::Document.new | |
doc.text(LOREM) | |
doc.render_file('/tmp/prawn_vs_pdfkit/benchmark_prawn.pdf') | |
end | |
Benchmark.bm(WIDTH) do |b| | |
b.report("PDFKit:") { for i in 0..TIMES; do_pdfkit; end } | |
b.report("Prawn: ") { for i in 0..TIMES; do_prawn; end } | |
end |
Your First Gist:
user system total real
PDFKit: 0.610000 0.770000 83.560000 (115.196074)
Prawn: 59.120000 0.340000 59.460000 ( 59.782119)
Your latest Gist:
user system total real
PDFKit: 0.590000 0.740000 82.560000 (111.891193)
Prawn: 57.630000 0.310000 57.940000 ( 57.975075)
Specs - Ruby 1.9.2p180
2.53GHz Intel Core i5
4 gb ram
Nice... looks like not doing extra superflous work improves performance time slightly :) (e.g. trying to freeze constants that hold fixnums...)
Seeing this kind of test, with our two machines, one generation apart was cool too. the i5 vs core 2 duo.
Cdog, i use pdfkit to print out an html invoice page. I couldn't figure out how to do it as easy as pdfkit... I'd love to see a test on that.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You're right about not needing #freeze... I used for because according to this benchmark: http://www.ruby-doc.org/stdlib/libdoc/benchmark/rdoc/classes/Benchmark.html#M000010 it's a little faster, but times is cleaner, and the speed difference is probably trivial in this case. Thanks!