Ubuntu 10.04 64bit Core i7-2600 (Sandy Bridge)
Digest::SHA 5.80
Digest::SHA1 2.13
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1)
== For small files Digest::SHA1 is much faster
use strict;
use warnings;
use Digest::SHA ();
use Digest::SHA1 ();
use Benchmark qw(cmpthese);
my $key = 1234567890;
cmpthese -1, {
'Digest::SHA::sha' => sub { Digest::SHA::sha1($key) },
'Digest::SHA1::sha1' => sub { Digest::SHA1::sha1($key) },
}
Rate Digest::SHA::sha Digest::SHA1::sha1
Digest::SHA::sha 811471/s -- -62%
Digest::SHA1::sha1 2123852/s 162% --
== For big files (i.e. more than 1kb) Digest::SHA is faster
use strict;
use warnings;
use Digest::SHA ();
use Digest::SHA1 ();
use Benchmark qw(cmpthese);
my $key = 'x' x (1024*1024*100);
cmpthese -1, {
'Digest::SHA::sha' => sub { Digest::SHA::sha1($key) },
'Digest::SHA1::sha1' => sub { Digest::SHA1::sha1($key) },
}
(warning: too few iterations for a reliable count)
Rate Digest::SHA1::sha1 Digest::SHA::sha
Digest::SHA1::sha1 2.27/s -- -27%
Digest::SHA::sha 3.12/s 38% --
Show quoted text> The time taken to compute the digest of a small password is not
noticeable, and is almost certainly smaller than the margin of timing
error.
Show quoted text> the performance issue isn't particularly relevant in that case,
Not always
1) In case we write code like this
cmpthese -1, {
'Digest::SHA::sha' => sub { Digest::SHA::sha1($key) for (1..100) },
'Digest::SHA1::sha1' => sub { Digest::SHA1::sha1($key) for (1..100) },
}
there should be any timing error
2) Performance on small inputs is important for example
a) if you generate things like Rainbow tables when writing security
applications.
b) Real example - I had to do _integration_ (regression) test for Tree
Hash based on SHA256 (CPAN Net::Amazon::TreeHash), so I used small
chunks like ~ 10 bytes,
and this test is slower part of my testsuite. Most time consumed in SHA266.
On Mon Jul 13 03:11:32 2009, MSHELOR wrote:
Show quoted text> Gisle crafted his benchmark to use large data sets because that is the
> only case where relative digest performance is significant or even
> detectable. The time taken to compute the digest of a small password is
> not noticeable, and is almost certainly smaller than the margin of
> timing error.
>
> So, even if the use-case of small inputs is far more common, it doesn't
> matter: the performance issue isn't particularly relevant in that case,
> and wouldn't likely vary much from implementation to implementation, or
> even from algorithm to algorithm.
>
> That said, the Digest::SHA module still appears to be faster than
> Digest::SHA1, even on small inputs. Here's the result I get using your
> benchmark code on Intel/Linux:
>
> Rate Digest::SHA1::sha1 Digest::SHA::sha
> Digest::SHA1::sha1 164549/s -- -36%
> Digest::SHA::sha 258306/s 57% --
>
> Mark