2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use PublicInbox::TestCommon;
7 use Benchmark qw(:all);
8 use PublicInbox::Inbox;
10 use PublicInbox::WwwStream;
12 my $inboxdir = $ENV{GIANT_INBOX_DIR} // $ENV{GIANT_PI_DIR};
13 my $blob = $ENV{TEST_BLOB};
14 my $obfuscate = $ENV{PI_OBFUSCATE} ? 1 : 0;
15 diag "PI_OBFUSCATE=$obfuscate";
16 plan skip_all => "GIANT_INBOX_DIR not defined for $0" unless $inboxdir;
18 my @cat = qw(cat-file --buffer --batch-check --batch-all-objects);
19 if (require_git(2.19, 1)) {
20 push @cat, '--unordered';
23 "git <2.19, cat-file lacks --unordered, locality suffers\n";
25 require_mods qw(Plack::Util);
26 my $ibx = PublicInbox::Inbox->new({ inboxdir => $inboxdir, name => 'name',
27 obfuscate => $obfuscate});
29 my $fh = $blob ? undef : $git->popen(@cat);
32 vec($vec, fileno($fh), 1) = 1;
33 select($vec, undef, undef, 60) or
34 die "timed out waiting for --batch-check";
38 env => { HTTP_HOST => 'example.com', 'psgi.url_scheme' => 'https' },
40 www => Plack::Util::inline_object(style => sub {''}),
41 gz => PublicInbox::GzipFilter::gzip_or_die(),
42 }, 'PublicInbox::WwwStream';
43 my ($eml, $res, $oid, $type);
47 $ctx->{mhref} = '../';
50 $eml = PublicInbox::Eml->new(shift);
51 $eml->each_part(\&PublicInbox::View::add_text_body, $ctx, 1);
52 $ctx->zflush(grep defined, delete @$ctx{'obuf'}); # compat
55 ${$ctx->{obuf}} = ''; # compat
56 $ctx->{gz} = PublicInbox::GzipFilter::gzip_or_die();
59 my $t = timeit(1, sub {
61 my $nr = $ENV{NR} // 10000;
64 $git->cat_async($blob, $cb);
68 ($oid, $type) = split / /;
69 next if $type ne 'blob';
71 $git->cat_async($oid, $cb);
76 diag 'add_text_body took '.timestr($t)." for $n <=> $m messages";
77 is($m, $n, 'rendered all messages');