Dear all,

Recently I discovered, thanks to people of this forum the use of Benchmark. A great powerful tool comparing speeds, processes and times.

Well since I love playing around with details I could not resist to make this make not useful test and compare the Config::IniFiles Vs Config::Simple.I decided to run an experiment and observe the output.

Update:

Thanks to Anonymous Monk and davido for their contributions and suggestions, I have modified my experiment and came up with new data.

The experimental code:

#!/usr/bin/perl use strict; use warnings; use List::Compare; use Config::Simple; use Config::IniFiles; use Fcntl qw(:flock); use Benchmark qw(:all) ; use Data::Dumper qw(Dumper); $|=1; #flush every time the program =flock sub LOCK_SH { 1 } ## shared lock sub LOCK_EX { 2 } ## exclusive lock sub LOCK_NB { 4 } ## non-blocking sub LOCK_UN { 8 } ## unlock =cut my %information; my $path = 'conf.ini'; my $count = -5 || die "Need a count!\n"; sub complex { open my $fh , '<' , "".$path."" or die "Could not open file: ".$path." - $!\n"; flock($fh, LOCK_SH) or die "Could not lock '".$fh."' - $!\n"; tie my %ini, 'Config::IniFiles', ( -file => "".$path."" ) or die "Error: IniFiles->new: @Config::IniFiles::errors"; close ($fh) or die "Could not close '".$path."' - $!\n"; print Dumper(\%ini); return %ini; } # end sub complex sub val { open my $fr , '<' , "".$path."" or die "Could not open file: ".$path." - $!\n"; flock($fr, LOCK_SH) or die "Could not lock '".$fr."' - $!\n"; my $cfg = Config::IniFiles->new( -file => "".$path."" ) or die "error: IniFiles->new: @Config::IniFiles::errors"; close ($fr) or die "Could not close '".$path."' - $!\n"; my $values = $cfg->val( 'Perl', 'test' ); my @array = split(',', $values); print Dumper(\@array); return @array; } # End of sub val sub simple { open my $fr , '<' , "".$path."" or die "Could not open file: ".$path." - $!\n"; flock($fr, LOCK_SH) or die "Could not lock '".$fr."' - $!\n"; Config::Simple->import_from( "".$path."", \%information) or die Config::Simple->error(); close ($fr) or die "Could not close '".$path."' - $!\n"; print Dumper(\%information); return %information; } # End of sub simple my $r = timethese ( $count , { 'complex' => '&complex', 'val' => '&val', 'simple' => '&simple' } ); cmpthese $r;

I am using a common conf.ini folder that both scripts are reading from with flock process applied since I am planning to use in combination with other scripts.

Sample of the conf.ini folder:

[Perl] test= bar,baz,foo,quux

The results after the test are the following:

val: 6 wallclock secs ( 5.69 usr + 0.30 sys = 5.99 CPU) @ 989.98/s +(n=5930) Rate complex val simple complex 700/s -- -29% -46% val 990/s 41% -- -24% simple 1297/s 85% 31% --

Well to be honest I was expecting the complex version of Config::IniFiles to be faster in comparison to Config::Simple due to simplicity of the code. But the results have proved my assumption wrong. Thanks to Anonymous Monk that he elaborate regarding the tie and OOP process I decided to add also the val process to make it more fair. Also davido point out that the unlock process is a trap and possibly the data can still remain within the process, so it is better to close the file in order to flush the output.

Again thank you all for your contribution, to beginners like my self this is a big boost on the learning curve.

Well I do not know if this comparison makes any sense to anyone. But since I am beginner and all of this stuff make a huge impression, I felt it would be nice to mention this. Just in case that someone needs to use one of these two solutions to get also an idea about speed.


In reply to RFC: config::simple vs config::ini by thanos1983

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.