Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

mpeters (5802)

  (email not shown publicly)
AOL IM: michael00peters (Add Buddy, Send Message)

Technorati Profile []

Journal of mpeters (5802)

Thursday March 09, 2006
04:40 PM

HTML Form filling benchmarks

[ #28943 ]
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 HTML::FillInForm has to parse the entire HTML, find the <form> and the inputs and then change the HTML to include all the values and selected="selected" 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 ~]$ ./
      Rate  hte  fif
hte 44.2/s   -- -27%
fif 60.6/s  37%   --
[mpeters@localhost ~]$ ./
      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

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();

        scalarref => \$out,
        fdat      => \%values,

sub fill_tmpl {
    my $tmpl = HTML::Template::Expr->new(
        filename => 'tmpl_text.tmpl',
        cache    => 1,

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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • 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 [].
    • 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.