Created
August 20, 2011 12:51
-
-
Save azumakuniyuki/1159068 to your computer and use it in GitHub Desktop.
Net::SMTP vs. Email::Send vs. Email::Sender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
# Net::SMTP vs. Email::Send vs. Email::Sender | |
{ | |
package NS1; | |
use strict; | |
use warnings; | |
use Net::SMTP; | |
sub sendmesg { | |
my $name = shift(); | |
my $from = shift(); | |
my $rcpt = shift(); | |
my $mesg = shift(); | |
my $smtp = Net::SMTP->new( | |
'Host' => '127.0.0.1', | |
'Port' => 2500, | |
'Hello' => '[127.0.0.1]' ); | |
$smtp->mail('<'.$from.'>'); | |
$smtp->to('<'.$rcpt.'>'); | |
$smtp->data(); | |
$smtp->datasend($mesg->as_string); | |
$smtp->quit(); | |
} | |
} | |
{ | |
package ES1; | |
use strict; | |
use warnings; | |
use Email::Send; | |
sub sendmesg { | |
my $name = shift(); | |
my $from = shift(); | |
my $rcpt = shift(); | |
my $mesg = shift(); | |
my $smtp = Email::Send->new( { | |
'mailer' => 'SMTP', | |
'mailer_args' => [ | |
'Host' => '127.0.0.1', | |
'Port' => 2500, | |
], | |
} ); | |
$smtp->send( $mesg ); | |
} | |
} | |
{ | |
package ES2; | |
use strict; | |
use warnings; | |
use Email::Sender::Simple 'sendmail'; | |
use Email::Sender::Transport::SMTP; | |
sub sendmesg { | |
my $name = shift(); | |
my $from = shift(); | |
my $rcpt = shift(); | |
my $mesg = shift(); | |
my $smtp = Email::Sender::Transport::SMTP->new( | |
'host' => '127.0.0.1', | |
'port' => 2500, | |
'helo' => '[127.0.0.1]' ); | |
return sendmail( $mesg, { | |
'from' => $from, | |
'to' => $rcpt, | |
'transport' => $smtp } ); | |
} | |
} | |
{ | |
package main; | |
use strict; | |
use warnings; | |
use Benchmark qw(:all); | |
use Test::More 'no_plan'; | |
use Email::MIME; | |
use Email::MIME::Creator; | |
my $S = '[email protected]'; | |
my $R = '[email protected]'; | |
my $M = Email::MIME->create( | |
'header' => [ | |
'From' => $S, | |
'To' => $R, | |
'Subject' => 'TEST', | |
], | |
'attributes' => { | |
'content_type' => 'text/plain', | |
'charset' => 'ISO-8859-1', | |
'encoding' => '7bit', | |
}, | |
'body' => 'TEST', | |
); | |
ok( ES1->sendmesg($S,$R,$M), 'Email::Send' ); | |
ok( ES2->sendmesg($S,$R,$M), 'Email::Sender' ); | |
ok( NS1->sendmesg($S,$R,$M), 'Net::SMTP' ); | |
cmpthese(100, { | |
'Net::SMTP' => sub { NS1->sendmesg($S,$R,$M); }, | |
'Email::Send' => sub { ES1->sendmesg($S,$R,$M); }, | |
'Email::Sender' => sub { ES2->sendmesg($S,$R,$M); }, | |
}); | |
} | |
__END__ | |
* PowerBookG4/perl 5.10.0 | |
ok 1 - Email::Send | |
ok 2 - Email::Sender | |
ok 3 - Net::SMTP | |
Rate Email::Send Email::Sender Net::SMTP | |
Email::Send 75.8/s -- -39% -55% | |
Email::Sender 125/s 65% -- -25% | |
Net::SMTP 167/s 120% 33% -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment