Skip to content

Instantly share code, notes, and snippets.

@lestrrat
Created March 11, 2010 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lestrrat/328974 to your computer and use it in GitHub Desktop.
Save lestrrat/328974 to your computer and use it in GitHub Desktop.
use strict;
use AnyEvent;
use AnyEvent::AIO;
use IO::AIO;
use Fcntl;
use Benchmark qw(cmpthese);
foreach my $size (10, 100, 1000, 10_000, 100_000) {
my $file = "/tmp/benchmark.dat";
my $buffer = ("1" x $size) . "\n";
my $length = length $buffer;
print "Comparing with buffer size $size...\n";
cmpthese( 100, {
aio => sub {
my $cv = AE::cv;
my $grp = aio_group sub { $cv->send };
$grp->add(
aio_open $file, O_WRONLY|O_CREAT|O_APPEND, 0644, sub {
my $fh = shift or die "failed :$!";
aio_write $fh, -1, $length, $buffer, 0, sub {};
}
) for 1..100;
$cv->recv;
unlink $file;
},
normal => sub {
for (1..100) {
open(my $fh, '>>', $file);
print $fh $buffer;
close($fh);
}
unlink $file;
},
});
}
__END__
Comparing with buffer size 10...
Rate normal aio
normal 80.0/s -- -19%
aio 99.0/s 24% --
Comparing with buffer size 100...
Rate normal aio
normal 80.0/s -- -18%
aio 97.1/s 21% --
Comparing with buffer size 1000...
Rate normal aio
normal 76.9/s -- -13%
aio 88.5/s 15% --
Comparing with buffer size 10000...
Rate normal aio
normal 52.4/s -- -27%
aio 71.9/s 37% --
Comparing with buffer size 100000...
Rate normal aio
normal 15.9/s -- -63%
aio 42.7/s 169% --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment