]> Sergey Matveev's repositories - public-inbox.git/blob - t/perf-msgview.t
t/perf-msgview: add test to check msg_html performance
[public-inbox.git] / t / 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 require './t/common.perl';
10
11 my @cat = qw(cat-file --buffer --batch-check --batch-all-objects);
12 if (require_git(2.19, 1)) {
13         push @cat, '--unordered';
14 } else {
15         warn
16 "git <2.19, cat-file lacks --unordered, locality suffers\n";
17 }
18
19 my $pi_dir = $ENV{GIANT_PI_DIR};
20 plan skip_all => "GIANT_PI_DIR not defined for $0" unless $pi_dir;
21
22 my $ibx = PublicInbox::Inbox->new({ mainrepo => $pi_dir, name => 'name' });
23 my $git = $ibx->git;
24 my $fh = $git->popen(@cat);
25 my $vec = '';
26 vec($vec, fileno($fh), 1) = 1;
27 select($vec, undef, undef, 60) or die "timed out waiting for --batch-check";
28
29 my $ctx = {
30         env => { HTTP_HOST => 'example.com', 'psgi.url_scheme' => 'https' },
31         -inbox => $ibx,
32 };
33 my ($str, $mime, $res, $cmt, $type);
34 my $n = 0;
35 my $t = timeit(1, sub {
36         while (<$fh>) {
37                 ($cmt, $type) = split / /;
38                 next if $type ne 'blob';
39                 ++$n;
40                 $str = $git->cat_file($cmt);
41                 $mime = PublicInbox::MIME->new($str);
42                 $res = PublicInbox::View::msg_html($ctx, $mime);
43                 $res = $res->[2];
44                 while (defined($res->getline)) {}
45                 $res->close;
46         }
47 });
48 diag 'msg_html took '.timestr($t)." for $n messages";
49 ok 1;
50 done_testing();