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.


In reply to Re^4: pdf with too long lines by Anonymous Monk
in thread pdf with too long lines by Dirk80

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.