]> Sergey Matveev's repositories - public-inbox.git/blob - xt/perf-msgview.t
xt/perf-msgview: modernize, support TEST_BLOB
[public-inbox.git] / xt / perf-msgview.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::Spawn qw(popen_rd);
11
12 my $inboxdir = $ENV{GIANT_INBOX_DIR} // $ENV{GIANT_PI_DIR};
13 my $blob = $ENV{TEST_BLOB};
14 plan skip_all => "GIANT_INBOX_DIR not defined for $0" unless $inboxdir;
15
16 my @cat = qw(cat-file --buffer --batch-check --batch-all-objects);
17 if (require_git(2.19, 1)) {
18         push @cat, '--unordered';
19 } else {
20         warn
21 "git <2.19, cat-file lacks --unordered, locality suffers\n";
22 }
23 require_mods qw(Plack::Util);
24 use_ok 'Plack::Util';
25 my $ibx = PublicInbox::Inbox->new({ inboxdir => $inboxdir, name => 'name' });
26 my $git = $ibx->git;
27 my $fh = $blob ? undef : $git->popen(@cat);
28 if ($fh) {
29         my $vec = '';
30         vec($vec, fileno($fh), 1) = 1;
31         select($vec, undef, undef, 60) or
32                 die "timed out waiting for --batch-check";
33 }
34
35 my $ctx = {
36         env => { HTTP_HOST => 'example.com', 'psgi.url_scheme' => 'https' },
37         ibx => $ibx,
38         www => Plack::Util::inline_object(style => sub {''}),
39 };
40 my ($mime, $res, $oid, $type);
41 my $n = 0;
42 my $obuf = '';
43 my $m = 0;
44
45 my $cb = sub {
46         $mime = PublicInbox::Eml->new(shift);
47         PublicInbox::View::multipart_text_as_html($mime, $ctx);
48         ++$m;
49         $obuf = '';
50 };
51
52 my $t = timeit(1, sub {
53         $ctx->{obuf} = \$obuf;
54         $ctx->{mhref} = '../';
55         if (defined $blob) {
56                 my $nr = $ENV{NR} // 10000;
57                 for (1..$nr) {
58                         ++$n;
59                         $git->cat_async($blob, $cb);
60                 }
61         } else {
62                 while (<$fh>) {
63                         ($oid, $type) = split / /;
64                         next if $type ne 'blob';
65                         ++$n;
66                         $git->cat_async($oid, $cb);
67                 }
68         }
69         $git->cat_async_wait;
70 });
71 diag 'multipart_text_as_html took '.timestr($t)." for $n <=> $m messages";
72 is($m, $n, 'rendered all messages');
73 done_testing();