]> Sergey Matveev's repositories - public-inbox.git/blob - xt/perf-obfuscate.t
640309d2cbc6f3fb2aa694f96950de28dc3173cb
[public-inbox.git] / xt / perf-obfuscate.t
1 #!perl -w
2 # Copyright (C) 2021 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
11 my $inboxdir = $ENV{GIANT_INBOX_DIR};
12 plan skip_all => "GIANT_INBOX_DIR not defined for $0" unless $inboxdir;
13
14 my $obfuscate = $ENV{PI_OBFUSCATE} ? 1 : 0;
15 diag "obfuscate=$obfuscate\n";
16
17 my @cat = qw(cat-file --buffer --batch-check --batch-all-objects);
18 if (require_git(2.19, 1)) {
19         push @cat, '--unordered';
20 } else {
21         warn
22 "git <2.19, cat-file lacks --unordered, locality suffers\n";
23 }
24 require_mods qw(Plack::Util);
25 use_ok '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 = {
35         env => { HTTP_HOST => 'example.com', 'psgi.url_scheme' => 'https' },
36         ibx => $ibx,
37         www => Plack::Util::inline_object(style => sub {''}),
38 };
39 my ($mime, $res, $oid, $type);
40 my $n = 0;
41 my $obuf = '';
42 my $m = 0;
43
44 my $cb = sub {
45         $mime = PublicInbox::Eml->new(shift);
46         PublicInbox::View::multipart_text_as_html($mime, $ctx);
47         ++$m;
48         $obuf = '';
49 };
50
51 my $t = timeit(1, sub {
52         $ctx->{obuf} = \$obuf;
53         $ctx->{mhref} = '../';
54         while (<$fh>) {
55                 ($oid, $type) = split / /;
56                 next if $type ne 'blob';
57                 ++$n;
58                 $git->cat_async($oid, $cb);
59         }
60         $git->async_wait_all;
61 });
62 diag 'multipart_text_as_html took '.timestr($t)." for $n <=> $m messages";
63 is($m, $n, 'rendered all messages');
64 done_testing();