diff options
author | Eric Wong <e@80x24.org> | 2023-01-29 10:30:41 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-01-30 06:42:31 +0000 |
commit | e6aa13bccb7ea5d5b3246b3a944621515905e360 (patch) | |
tree | 822309b8cc2ac85ba50acd33deebb03891b0844b /t | |
parent | 9eb8baf199cd148b7ebf8e6e130fb832f4e1ef00 (diff) | |
download | public-inbox-e6aa13bccb7ea5d5b3246b3a944621515905e360.tar.gz |
On my x86-64 machine, OpenSSL SHA-256 is nearly twice as fast as the Digest::SHA implementation from Perl, most likely due to an optimized assembly implementation. SHA-1 is a few percent faster, too.
Diffstat (limited to 't')
-rw-r--r-- | t/clone-coderepo.t | 2 | ||||
-rw-r--r-- | t/httpd-corner.psgi | 4 | ||||
-rw-r--r-- | t/httpd-corner.t | 2 | ||||
-rw-r--r-- | t/ipc.t | 6 | ||||
-rw-r--r-- | t/nntpd.t | 4 | ||||
-rw-r--r-- | t/sha.t | 25 | ||||
-rw-r--r-- | t/www_listing.t | 2 |
7 files changed, 35 insertions, 10 deletions
diff --git a/t/clone-coderepo.t b/t/clone-coderepo.t index 2e628963..1f33a6d7 100644 --- a/t/clone-coderepo.t +++ b/t/clone-coderepo.t @@ -6,7 +6,7 @@ use PublicInbox::TestCommon; use PublicInbox::Import; use File::Temp; use File::Path qw(remove_tree); -use Digest::SHA qw(sha1_hex); +use PublicInbox::SHA qw(sha1_hex); require_mods(qw(json Plack::Builder HTTP::Date HTTP::Status)); require_git '1.8.5'; require_ok 'PublicInbox::LeiMirror'; diff --git a/t/httpd-corner.psgi b/t/httpd-corner.psgi index ea643024..1e96d7b1 100644 --- a/t/httpd-corner.psgi +++ b/t/httpd-corner.psgi @@ -4,7 +4,7 @@ # Usage: plackup [OPTIONS] /path/to/this/file use v5.12; use Plack::Builder; -require Digest::SHA; +require PublicInbox::SHA; if (defined(my $f = $ENV{TEST_OPEN_FIFO})) { open my $fh, '>', $f or die "open($f): $!"; say $fh 'hi'; @@ -29,7 +29,7 @@ my $app = sub { my $h = [ 'Content-Type' => 'text/plain' ]; my $body = []; if ($path eq '/sha1') { - my $sha1 = Digest::SHA->new('SHA-1'); + my $sha1 = PublicInbox::SHA->new(1); my $buf; while (1) { my $r = $in->read($buf, 4096); diff --git a/t/httpd-corner.t b/t/httpd-corner.t index 88820270..7600c2b9 100644 --- a/t/httpd-corner.t +++ b/t/httpd-corner.t @@ -7,7 +7,7 @@ use strict; use v5.10.1; use PublicInbox::TestCommon; use Time::HiRes qw(gettimeofday tv_interval); use PublicInbox::Spawn qw(spawn popen_rd); require_mods(qw(Plack::Util Plack::Builder HTTP::Date HTTP::Status)); -use Digest::SHA qw(sha1_hex); +use PublicInbox::SHA qw(sha1_hex); use IO::Handle (); use IO::Socket::UNIX; use Fcntl qw(:seek); @@ -1,19 +1,19 @@ #!perl -w -# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org> +# Copyright (C) all contributors <meta@public-inbox.org> # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> use strict; use v5.10.1; use Test::More; use PublicInbox::TestCommon; use Fcntl qw(SEEK_SET); -use Digest::SHA qw(sha1_hex); +use PublicInbox::SHA qw(sha1_hex); require_mods(qw(Storable||Sereal)); require_ok 'PublicInbox::IPC'; my ($tmpdir, $for_destroy) = tmpdir(); state $once = eval <<''; package PublicInbox::IPC; use strict; -use Digest::SHA qw(sha1_hex); +use PublicInbox::SHA qw(sha1_hex); sub test_array { qw(test array) } sub test_scalar { 'scalar' } sub test_scalarref { \'scalarref' } @@ -7,7 +7,7 @@ use PublicInbox::Eml; use Socket qw(IPPROTO_TCP TCP_NODELAY); use Sys::Hostname; use POSIX qw(_exit); -use Digest::SHA; +use PublicInbox::SHA; # t/nntpd-v2.t wraps this for v2 my $version = $ENV{PI_TEST_VERSION} || 1; @@ -304,7 +304,7 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000 my %sums; for (1..$nart) { <$s> =~ /\A220 / or _exit(4); - my $dig = Digest::SHA->new(1); + my $dig = PublicInbox::SHA->new(1); while (my $l = <$s>) { last if $l eq ".\r\n"; $dig->add($l); diff --git a/t/sha.t b/t/sha.t new file mode 100644 index 00000000..2e2d5636 --- /dev/null +++ b/t/sha.t @@ -0,0 +1,25 @@ +#!perl -w +# Copyright (C) all contributors <meta@public-inbox.org> +# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> +use v5.12; +use PublicInbox::SHA; +use Test::More; + +{ + my $dig = PublicInbox::SHA->new(1); + open my $fh, '<', 'COPYING' or die "open: $!"; + $dig->add(do { local $/; <$fh> }); + is($dig->hexdigest, '78e50e186b04c8fe1defaa098f1c192181b3d837', + 'AGPL-3 matches'); +} + +SKIP: { + my $n = $ENV{TEST_LEAK_NR} or skip 'TEST_LEAK_NR unset', 1; + for (1..$n) { + PublicInbox::SHA->new(1)->add('hello')->digest; + PublicInbox::SHA->new(1)->add('hello'); + PublicInbox::SHA->new(1); + } +} + +done_testing; diff --git a/t/www_listing.t b/t/www_listing.t index 6166b94e..4784c39d 100644 --- a/t/www_listing.t +++ b/t/www_listing.t @@ -5,7 +5,7 @@ use strict; use v5.10.1; use PublicInbox::TestCommon; use PublicInbox::Import; use IO::Uncompress::Gunzip qw(gunzip); -require_mods(qw(json URI::Escape Plack::Builder Digest::SHA HTTP::Tiny)); +require_mods(qw(json URI::Escape Plack::Builder HTTP::Tiny)); require PublicInbox::WwwListing; require PublicInbox::ManifestJsGz; use PublicInbox::Config; |