#!/usr/bin/perl -w use strict; use XML::Simple qw(:strict); use Time::HiRes qw(time); use File::stat; use Test::More qw(no_plan); my $xs; my $XMLFile = $ARGV[0]; my $size = stat($XMLFile)->size(); print "File $XMLFile is " . $size . " bytes\n"; my ($start, $end); $xs = XML::Simple->new(ForceArray => 0, KeyAttr => {}); my $backend = ''; my $xml_default; { local $ENV{XML_SIMPLE_PREFERRED_PARSER} = $backend; $start = time(); $xml_default = $xs->XMLin($XMLFile); $end = time(); } print_result($backend, $end, $start, $size); $backend = 'XML::Parser'; my $xml_x_p; { local $ENV{XML_SIMPLE_PREFERRED_PARSER} = $backend; $start = time(); $xml_x_p = $xs->XMLin($XMLFile); $end = time(); } print_result($backend, $end, $start, $size); $backend = 'XML::SAX::Expat'; my $xml_x_s_e; { local $ENV{XML_SIMPLE_PREFERRED_PARSER} = $backend; $start = time(); $xml_x_s_e = $xs->XMLin($XMLFile); $end = time(); } print_result($backend, $end, $start, $size); $backend = 'XML::LibXML::SAX'; my $xml_x_l_s; { local $ENV{XML_SIMPLE_PREFERRED_PARSER} = 'XML::LibXML::SAX'; $start = time(); $xml_x_l_s = $xs->XMLin($XMLFile); $end = time(); } print_result($backend, $end, $start, $size); is_deeply($xml_default, $xml_x_p); is_deeply($xml_default, $xml_x_s_e); is_deeply($xml_default, $xml_x_l_s); sub print_result { my ($backend, $end, $start, $size) = @_; my $duration = $end - $start; print "XML::Simple with $backend backend took ", sprintf("%02.4f", $duration), " seconds. "; print "This equates to ", sprintf("%02.4f", $size / ($duration)), " kilobytes per second (1024 bytes per k)\n"; }