]> Sergey Matveev's repositories - public-inbox.git/blob - xt/perf-msgview.t
8c9037ee215e019dd9664a4c694d5b7034eae627
[public-inbox.git] / xt / perf-msgview.t
1 # Copyright (C) 2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 use strict;
4 use warnings;
5 use Test::More;
6 use Benchmark qw(:all);
7 use PublicInbox::Inbox;
8 use PublicInbox::View;
9 use PublicInbox::TestCommon;
10
11 my $inboxdir = $ENV{GIANT_INBOX_DIR} // $ENV{GIANT_PI_DIR};
12 plan skip_all => "GIANT_INBOX_DIR not defined for $0" unless $inboxdir;
13
14 my @cat = qw(cat-file --buffer --batch-check --batch-all-objects);
15 if (require_git(2.19, 1)) {
16         push @cat, '--unordered';
17 } else {
18         warn
19 "git <2.19, cat-file lacks --unordered, locality suffers\n";
20 }
21 require_mods qw(Plack::Util);
22 use_ok 'Plack::Util';
23 my $ibx = PublicInbox::Inbox->new({ inboxdir => $inboxdir, name => 'name' });
24 my $git = $ibx->git;
25 my $fh = $git->popen(@cat);
26 my $vec = '';
27 vec($vec, fileno($fh), 1) = 1;
28 select($vec, undef, undef, 60) or die "timed out waiting for --batch-check";
29
30 my $ctx = {
31         env => { HTTP_HOST => 'example.com', 'psgi.url_scheme' => 'https' },
32         -inbox => $ibx,
33         www => Plack::Util::inline_object(style => sub {''}),
34 };
35 my ($str, $mime, $res, $cmt, $type);
36 my $n = 0;
37 my $t = timeit(1, sub {
38         while (<$fh>) {
39                 ($cmt, $type) = split / /;
40                 next if $type ne 'blob';
41                 ++$n;
42                 $str = $git->cat_file($cmt);
43                 $mime = PublicInbox::MIME->new($str);
44                 $res = PublicInbox::View::msg_html($ctx, $mime);
45                 $res = $res->[2];
46                 while (defined($res->getline)) {}
47                 $res->close;
48         }
49 });
50 diag 'msg_html took '.timestr($t)." for $n messages";
51 ok 1;
52 done_testing();