Skip to content

Instantly share code, notes, and snippets.

@seeflanigan
Created June 1, 2011 20:32
Show Gist options
  • Save seeflanigan/1003239 to your computer and use it in GitHub Desktop.
Save seeflanigan/1003239 to your computer and use it in GitHub Desktop.
Prawn vs PDFKit Benchmark
-> % ./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
#!/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
@pjammer
Copy link

pjammer commented Jun 2, 2011

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