A recent discussion titled MLDBM performance problem made me curious on the performance of MLDBM versus a DBMS such as MySQL.

Here is a Benchmark of a small, write/read intensive script.

#!/usr/bin/perl -sw use strict; use Benchmark qw (cmpthese); use MLDBM qw(DB_File Storable); use Fcntl; use DBI; our $N ||= 1e4; # ------ MLDBM variables my %hash = (); my $dbname = q{testmldbm.db}; my $dbm; # ------ MySQL variables my $dbh = undef; my %sths = (); # ------ MLDBM functions sub init_mldbm { $dbm = tie (%hash, 'MLDBM', $dbname, O_CREAT|O_RDWR, 0640) or die $! +; } sub write_mldbm { my ($key,$value) = @_; init_mldbm() unless $dbm; my $arref = $value; $hash{$key} = $arref; return $hash{$key}; } sub read_mldbm { my $key = shift; init_mldbm() unless $dbm; return (exists( $hash{$key} )) ? $hash{$key} : undef; } sub reset_mldbm { if (-f $dbname) { unlink($dbname) or die(qq{failed to unlink $dbname}); } } # ------ MySQL functions sub connect_mysql{ $dbh = DBI->connect('DBI:mysql:test', '...', '...'); die("connect failed") if(!$dbh); } sub write_mysql { my ($key,$value) = @_; connect_mysql() unless $dbh; my $sql = q{insert into mldbm(k,v) values(?,?)}; $sths{$sql} = $dbh->prepare($sql) unless $sths{$sql}; $sths{$sql}->execute($key, $value) or die(qq{execute failed using va +lue:$value}); } sub read_mysql { my $value = shift; connect_mysql() unless $dbh; my $sql = q{ select v from mldbm where k=? }; $sths{$sql} = $dbh->prepare($sql) unless $sths{$sql}; $sths{$sql}->execute($value) or die(qq{execute failed using value:$v +alue}); my $ary_ref = $sths{$sql}->fetchrow_hashref; return $ary_ref->{v}; } sub reset_mysql { connect_mysql() unless $dbh; my $sql = q{ delete from mldbm }; $sths{$sql} = $dbh->prepare($sql) unless $sths{$sql}; $sths{$sql}->execute() or die(qq{execute failed}); } # ------ main ------ reset_mldbm(); reset_mysql(); my ($i,$j) = (1,1); cmpthese($N, { mldbm => sub { write_mldbm($i,$i); read_mldbm($i++); }, mysql => sub { write_mysql($j,$j); read_mysql($j++); }, } ); __END__ =head1 NAME mldbm - Benchmark MLDBM vs MySQL =head1 MySQL commands mysql 4.1.20, Linux 2.6.9, ext3 file system, single IDE disk MySQL tables are MyISAM. create database mldbm; use mldbm; create table mldbm (k integer primary key, v integer not null); =head1 RESULTS $ ./mldbm.pl -N=1e4 Rate mysql mldbm mysql 4950/s -- -10% mldbm 5495/s 11% -- $ ./mldbm.pl -N=1e5 Rate mldbm mysql mldbm 4011/s -- -16% mysql 4778/s 19% -- $ ./mldbm.pl -N=2e5 Rate mldbm mysql mldbm 3798/s -- -23% mysql 4918/s 29% -- $ ./mldbm.pl -N=5e5 Rate mldbm mysql mldbm 4110/s -- -17% mysql 4928/s 20% -- =cut
It seems MLDBM is slightly faster than MySQL for smaller (<= 1e4) data sets, but as the data set size grows, MySQL seems to operate faster.

Comments please.

--
print map{chr}unpack(q{A3}x24,q{074117115116032097110111116104101114032080101114108032104097099107101114})

In reply to Benchmark MLDBM vs MySQL by andreas1234567

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.