]> Sergey Matveev's repositories - public-inbox.git/blob - xt/perf-obfuscate.t
4da361240f1dbf79ece5362c58d7d67fc400b742
[public-inbox.git] / xt / perf-obfuscate.t
1 #!perl -w
2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict;
5 use v5.10.1;
6 use PublicInbox::TestCommon;
7 use Benchmark qw(:all);
8 use PublicInbox::Inbox;
9 use PublicInbox::View;
10 use PublicInbox::WwwStream;
11
12 my $inboxdir = $ENV{GIANT_INBOX_DIR};
13 plan skip_all => "GIANT_INBOX_DIR not defined for $0" unless $inboxdir;
14
15 my $obfuscate = $ENV{PI_OBFUSCATE} ? 1 : 0;
16 diag "obfuscate=$obfuscate\n";
17
18 my @cat = qw(cat-file --buffer --batch-check --batch-all-objects);
19 if (require_git(2.19, 1)) {
20         push @cat, '--unordered';
21 } else {
22         warn
23 "git <2.19, cat-file lacks --unordered, locality suffers\n";
24 }
25 require_mods qw(Plack::Util);
26 my $ibx = PublicInbox::Inbox->new({ inboxdir => $inboxdir, name => 'name' ,
27                                     obfuscate => $obfuscate});
28 my $git = $ibx->git;
29 my $fh = $git->popen(@cat);
30 my $vec = '';
31 vec($vec, fileno($fh), 1) = 1;
32 select($vec, undef, undef, 60) or die "timed out waiting for --batch-check";
33
34 my $ctx = bless {
35         env => { HTTP_HOST => 'example.com', 'psgi.url_scheme' => 'https' },
36         ibx => $ibx,
37         www => Plack::Util::inline_object(style => sub {''}),
38         gz => PublicInbox::GzipFilter::gzip_or_die(),
39 }, 'PublicInbox::WwwStream';
40 my ($eml, $res, $oid, $type);
41 my $n = 0;
42 my $m = 0;
43 ${$ctx->{obuf}} = '';
44 $ctx->{mhref} = '../';
45
46 my $cb = sub {
47         $eml = PublicInbox::Eml->new(shift);
48         $eml->each_part(\&PublicInbox::View::add_text_body, $ctx, 1);
49         $ctx->zflush;
50         ++$m;
51         delete $ctx->{zbuf};
52         ${$ctx->{obuf}} = '';
53 };
54
55 my $t = timeit(1, sub {
56         while (<$fh>) {
57                 ($oid, $type) = split / /;
58                 next if $type ne 'blob';
59                 ++$n;
60                 $git->cat_async($oid, $cb);
61         }
62         $git->async_wait_all;
63 });
64 diag 'add_text_body took '.timestr($t)." for $n <=> $m messages";
65 is($m, $n, 'rendered all messages');
66 done_testing();