HTML Form filling benchmarks

mpeters on 2006-03-09T21:40:05

Every web application needs to fill in HTML <form>s at some point. Simple text <input>s and <textarea>s are easy to do. But radio buttons, checkboxes and <select>s are a bit harder.

I love HTML::FillInForm because each form <input> is treated the same. It doesn't matter if the designer wants to change from a <select> box to radio boxes, or replace it with a text <input>. The code that fills it doesn't change.

But stuff. That's gotta be slow, right?

So, to see how slow I decided to benchmark it (against
HTML::Template::Expr). Here's the results (code benchmarked is at the bottom):
With small, fairly simple forms, and using external files so H::T::E could cache -

For 1000 iterations:

Rate hte fif hte 1493/s -- -7% fif 1613/s 8% --

Rate fif hte fif 1075/s -- -11% hte 1205/s 12% --


And it usually went back and forth like that. They were both very close and the winner flipped-flopped.

Now with a very large complicated HTML
with lots of other markup taken straight from a client's site:
[mpeters@localhost ~]$ ./bench.pl
      Rate  hte  fif
hte 44.2/s   -- -27%
fif 60.6/s  37%   --
[mpeters@localhost ~]$ ./bench.pl
      Rate  hte  fif
hte 41.8/s   -- -36%
fif 65.4/s  56%   --


FillInForm consistently beat H::T::E on this large form. I was pretty amazed. If you see any problems with my benchmark, please let me know.

Benchmark code
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark qw(:all);
use HTML::FillInForm;
use HTML::Template::Expr;
use HTML::Template;

my %values = ( prefix => 'Mr.', first_name => 'Michael', last_name => 'Peters', address1 => '1234 Main St.', city => 'Silver Spring', state => 'Maryland', zip => '12345', country => 'US', );

sub fill_form { my $tmpl = HTML::Template->new( filename => 'form_text.tmpl', cache => 1, ); my $out = $tmpl->output();

HTML::FillInForm->new()->fill( scalarref => \$out, fdat => \%values, ); }

sub fill_tmpl { my $tmpl = HTML::Template::Expr->new( filename => 'tmpl_text.tmpl', cache => 1, ); $tmpl->param(%values); $tmpl->output(); }

cmpthese( 1000, { hte => sub { fill_tmpl() }, fif => sub { fill_form() }, }, );


Faster HTML::FillInForm

Hansen on 2006-03-10T18:00:29

And if you want a faster version of HTML::FillInForm you could try an unreleased and untested version based on XML::LibXML, HTML::FillInForm::LibXML.

Re:Faster HTML::FillInForm

mpeters on 2006-03-10T22:47:44

I tried to run my benchmark against using this too, and it seemed to be extremely fast (even with a lot of libxml warnings about various constructs in the HTML). But then I looked at the output and it didn't actually fill the form in. Very strange since it did parse the HTML. Maybe I did something wrong... I'll keep looking.