2 # Copyright (C) 2019-2020 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use Benchmark qw(:all);
8 use PublicInbox::TestCommon;
9 my $git_dir = $ENV{GIANT_GIT_DIR};
10 plan 'skip_all' => "GIANT_GIT_DIR not defined for $0" unless defined($git_dir);
11 use_ok 'PublicInbox::Git';
12 my $git = PublicInbox::Git->new($git_dir);
13 my @cat = qw(cat-file --buffer --batch-check --batch-all-objects);
14 if (require_git(2.19, 1)) {
15 push @cat, '--unordered';
17 warn "git <2.19, cat-file lacks --unordered, locality suffers\n";
20 my $nr = $ENV{NR} || 1;
22 my $async = timeit($nr, sub {
23 my $dig = Digest::SHA->new(1);
28 my $cat = $git->popen(@cat);
31 my ($oid, undef, undef) = split(/ /);
32 $git->cat_async($oid, $cb);
34 close $cat or die "cat: $?";
36 push @dig, ['async', $dig->hexdigest ];
39 my $sync = timeit($nr, sub {
40 my $dig = Digest::SHA->new(1);
41 my $cat = $git->popen(@cat);
43 my ($oid, undef, undef) = split(/ /);
44 my $bref = $git->cat_file($oid);
47 close $cat or die "cat: $?";
48 push @dig, ['sync', $dig->hexdigest ];
51 ok(scalar(@dig) >= 2, 'got some digests');
54 isnt($exp, Digest::SHA->new(1)->hexdigest, 'not empty');
56 is($_->[1], $exp, "digest matches $_->[0] <=> $ref->[0]");
58 diag "sync=".timestr($sync);
59 diag "async=".timestr($async);