From 499af0138412496c2a0c84035d5d398fac178624 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 10 Jun 2020 07:04:13 +0000 Subject: imap: split out unit tests and benchmarks This makes the test code easier-to-manage and allows us to run faster unit tests which don't involve loading Mail::IMAPClient. --- xt/perf-imap-list.t | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 xt/perf-imap-list.t (limited to 'xt') diff --git a/xt/perf-imap-list.t b/xt/perf-imap-list.t new file mode 100644 index 00000000..37640a90 --- /dev/null +++ b/xt/perf-imap-list.t @@ -0,0 +1,35 @@ +#!perl -w +# Copyright (C) 2020 all contributors +# License: AGPL-3.0+ +use Test::More; +use_ok 'PublicInbox::IMAP'; +use_ok 'PublicInbox::IMAPD'; +use PublicInbox::DS; +use Benchmark qw(:all); +my @n = map { { newsgroup => "inbox.comp.foo.bar.$_" } } (0..50000); +push @n, map { { newsgroup => "xobni.womp.foo.bar.$_" } } (0..50000); +my $self = { imapd => { grouplist => \@n } }; +PublicInbox::IMAPD::refresh_inboxlist($self->{imapd}); + +my $n = scalar @n; +open my $null, '>', '/dev/null' or BAIL_OUT "open: $!"; +my $ds = { sock => $null }; +my $nr = 200; +diag "starting benchmark..."; +my $cmd_list = \&PublicInbox::IMAP::cmd_list; +my $t = timeit(1, sub { + for (0..$nr) { + my $res = $cmd_list->($self, 'tag', '', '*'); + PublicInbox::DS::write($ds, $res); + } +}); +diag timestr($t). "list all for $n inboxes $nr times"; +$nr = 20; +$t = timeit(1, sub { + for (0..$nr) { + my $res = $cmd_list->($self, 'tag', 'inbox.', '%'); + PublicInbox::DS::write($ds, $res); + } +}); +diag timestr($t). "list partial for $n inboxes $nr times"; +done_testing; -- cgit v1.2.3-24-ge0c7