CGI-Ex

 view release on metacpan or  search on metacpan

samples/benchmark/bench_conf_writers.pl  view on Meta::CPAN

#yaml    250/s     --    -1%   -14%   -14%   -61%   -77%   -95%   -95%
#yaml2   254/s     1%     --   -13%   -13%   -60%   -77%   -95%   -95%
#sto     292/s    17%    15%     --    -0%   -54%   -73%   -94%   -95%
#pl      292/s    17%    15%     0%     --   -54%   -73%   -94%   -95%
#xml     636/s   155%   151%   118%   118%     --   -42%   -88%   -88%
#g_conf 1088/s   335%   329%   273%   272%    71%     --   -79%   -80%
#ini    5144/s  1958%  1929%  1662%  1660%   708%   373%     --    -3%
#sto2   5321/s  2029%  1999%  1723%  1721%   736%   389%     3%     --

my $str = {
  foo     => {key1 => "bar",   key2 => "ralph"},
  pass    => {key1 => "word",  key2 => "ralph"},
  garbage => {key1 => "can",   key2 => "ralph"},
  mighty  => {key1 => "ducks", key2 => "ralph"},
  quack   => {key1 => "moo",   key2 => "ralph"},
  one1    => {key1 => "val1",  key2 => "ralph"},
  one2    => {key1 => "val2",  key2 => "ralph"},
  one3    => {key1 => "val3",  key2 => "ralph"},
  one4    => {key1 => "val4",  key2 => "ralph"},
  one5    => {key1 => "val5",  key2 => "ralph"},
  one6    => {key1 => "val6",  key2 => "ralph"},
  one7    => {key1 => "val7",  key2 => "ralph"},
  one8    => {key1 => "val8",  key2 => "ralph"},
};

###----------------------------------------------------------------###

#         Rate   yaml  yaml2     pl    sto    xml g_conf   sto2
#yaml    736/s     --    -3%   -20%   -21%   -62%   -72%   -89%
#yaml2   755/s     3%     --   -18%   -19%   -61%   -71%   -89%
#pl      923/s    25%    22%     --    -1%   -53%   -65%   -86%
#sto     928/s    26%    23%     1%     --   -53%   -65%   -86%
#xml    1961/s   166%   160%   113%   111%     --   -26%   -71%
#g_conf 2635/s   258%   249%   185%   184%    34%     --   -61%
#sto2   6824/s   827%   803%   639%   635%   248%   159%     --

#$str = {
#  foo     => "bar",
#  pass    => "word",
#  garbage => "can",
#  mighty  => "ducks",
#  quack   => "moo",
#  one1    => "val1",
#  one2    => "val2",
#  one3    => "val3",
#  one4    => "val4",
#  one5    => "val5",
#  one6    => "val6",
#  one7    => "val7",
#  one8    => "val8",
#};

###----------------------------------------------------------------###

my $conf = eval $str;

my %TESTS = ();

### do perl
my $dir = File::Temp->newdir();
chmod 0755, $dir;
my $tmpnam = "$dir/bench";
my $file = $tmpnam. '.pl';
$TESTS{pl} = sub {
  $cob->write_ref($file, $str);
};
$files{pl} = $file;

### do a generic conf_write
my $file2 = $tmpnam. '.g_conf';
local $CGI::Ex::Conf::EXT_WRITERS{g_conf} = \&generic_conf_write;
$TESTS{g_conf} = sub {
  $cob->write_ref($file2, $str);
};
$files{g_conf} = $file2;


### load in the rest of the tests that we support
if (eval {require JSON}) {
  my $_file = $tmpnam. '.json';
  $TESTS{json} = sub {
    $cob->write_ref($file, $str);
  };
  $files{json} = $_file;
}

if (eval {require Storable}) {
  my $_file = $tmpnam. '.sto';
  $TESTS{sto} = sub {
    $cob->write_ref($file, $str);
  };
  $files{sto} = $_file;
}

if (eval {require Storable}) {
  my $_file = $tmpnam. '.sto2';
  $TESTS{sto2} = sub {
    &Storable::store($str, $_file);
  };
  $files{sto2} = $_file;
}

if (eval {require YAML}) {
  my $_file = $tmpnam. '.yaml';
  $TESTS{yaml} = sub {
    $cob->write_ref($_file, $str);
  };
  $files{yaml} = $_file;
}

if (eval {require YAML}) {
  my $_file = $tmpnam. '.yaml2';
  $TESTS{yaml2} = sub {
    &YAML::DumpFile($_file, $str);
  };
  $files{yaml2} = $_file;
}

if (eval {require Config::IniHash}) {
  my $_file = $tmpnam. '.ini';
  $TESTS{ini} = sub {



( run in 0.613 second using v1.01-cache-2.11-cpan-39bf76dae61 )