#!/usr/bin/perl -w use strict; use IO::Socket; use Benchmark; my $to_mail_addy = "junk\@????????.net"; my $from_mail_addy = "junk\@????????.net"; my $mailhost = "localhost"; sub with_pipe { open(SENDMAIL, "|/usr/sbin/sendmail") or die "cannot open sendmail"; print SENDMAIL "To: $to_mail_addy\n"; print SENDMAIL "From: $from_mail_addy\n"; print SENDMAIL "Subject: A speed test...\n"; print SENDMAIL "Content-type: text/plain \n\n"; print SENDMAIL "Blah blah blah... this is my content..."; close(SENDMAIL); } sub with_socket { my $sock = new IO::Socket::INET(PeerAddr => 'localhost', PeerPort => 25, Proto => 'tcp'); die "unable to create $sock" unless defined $sock; print $sock "Hello arino.net\n"; print $sock "MAIL FROM: $from_mail_addy\n"; print $sock "RCPT TO: $to_mail_addy\n"; print $sock "DATA\n"; print $sock "Subject: A speed test...\n"; print $sock "Blah blah blah... this is my content..."; print $sock ".\n"; print $sock "quit\n"; close($sock); } timethese (1000, {"WITH PIPES" => \&with_pipe, "WITH SOCKET" => \&with_socket }); [ed@darkness ed]$ perl speedtest.pl Benchmark: timing 1000 iterations of WITH PIPES, WITH SOCKET... WITH PIPES: 22 wallclock secs ( 0.26 usr 0.68 sys + 6.95 cusr 4.93 csys = 12.82 CPU) @ 1063.83/s (n=1000) WITH SOCKET: 17 wallclock secs ( 1.76 usr + 1.13 sys = 2.89 CPU) @ 346.02/s (n=1000)