in reply to Re^3: pdf with too long lines
in thread pdf with too long lines

comparing these parsers performance

Shall we?

use strict; use warnings; use feature 'say'; use Time::HiRes 'time'; use PDF::API2; use CAM::PDF; use PDF::Data; sub with_time ($&) { my ( $note, $code ) = @_; my $t = time; my $ret = &$code; printf "%-6.3f - %s\n", time - $t, $note; return $ret } my $fn = 'HigherOrderPerl-trimmed.pdf'; { say ' PDF::API2'; my $pdf = with_time '(1) open (and cache pages)', sub { PDF::API2->open( $fn ) }; with_time '(2) parse/cache everything', sub { $pdf->{ pdf }->read_objnum( $_, 0 ) for 1 .. $pdf->{ pdf }{' maxobj'} - 2 } } { say ' CAM::PDF'; my $pdf = with_time '(1) open', sub { CAM::PDF->new( $fn ) } ; with_time '(2) parse/cache page objects', sub { $pdf->getPage( $_ ) for 1 .. $pdf->numPages }; with_time '(3) parse/cache everything else', sub { $pdf->cacheObjects } } { say ' PDF::Data'; with_time '(1) open and parse everything', sub { PDF::Data->read_pdf( $fn, '-novalidate' => 1 ) } } __END__ PDF::API2 0.649 - (1) open (and cache pages) 1.067 - (2) parse/cache everything CAM::PDF 0.010 - (1) open 0.097 - (2) parse/cache page objects 0.095 - (3) parse/cache everything else PDF::Data 7.002 - (1) open and parse everything

Modules were created for different tasks/purposes; this comparison is not really practical, just for entertainment and additional proof, to self (though I don't need any), that one parser is superior to alternatives and why I'm using one and won't consider others for my usual purposes, which are inspection/analysis and minor pinpoint changes. If/when I need PDF generation (especially from scratch), there's no choice but PDF::API2.

Just to clarify, (a) PDF::API2 caches all pages to its internal stack on open, therefore I did additional step for CAM::PDF. And so, (1) + (2) for the latter is to be compared to (1) of the former. (b) PDF::Data also decompresses/inflates all streams (though we have prohibited validation), which takes ~0.5 seconds. It could be either disabled (patching source) or turned on for other participants, but I don't think it's important. The comparison is illustration of regex use efficiency to parse.