Skip to content

Commit

Permalink
Item11088: Add timing test showing wasted CPU
Browse files Browse the repository at this point in the history
Foswiki::Form's renderForDisplay is expanding all macros in a DataForm on each
view... which needlessly slows down list types that are populated from SEARCH
in the DataForm definition.

I'm not sure if this is fixable, but I'm hoping we can be more lazy about
expanding all those DataForm macros

git-svn-id: http://svn.foswiki.org/trunk@12872 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
PaulHarvey authored and PaulHarvey committed Oct 25, 2011
1 parent f5ed92d commit 92a3104
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions UnitTestContrib/test/unit/RenderFormTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ our @ISA = qw( FoswikiFnTestCase );

use Foswiki::Meta;
use File::Temp;
use Benchmark ':hireswallclock';

my $testtopic1 = 'TestTopic1';
my $testtopic2 = 'TestTopic2';
Expand Down Expand Up @@ -497,4 +498,57 @@ HERE
return;
}

# Item11088 - the aim of this test is to measure the performance of the
# select+multi+values formfield type when its default values are a static list
sub test_timing_static_multivalues {
my ($this) = @_;
my @topics = Foswiki::Func::getTopicList($Foswiki::cfg{SystemWebName});
my @list;

foreach my $topic ( @topics ) {
push(@list, Foswiki::Func::spaceOutWikiWord($topic) . '=' . $topic);
}
$this->timing_multivalues(20, join(', ', @list));

return;
}

sub test_timing_dynamic_multivalues {
my ($this) = @_;

$this->timing_multivalues(20, '%SEARCH{ "1" type="query" web="%SYSTEMWEB%" nonoise="on" nofinalnewline="on" format="$percntSPACEOUT{$topic}$percnt=$topic" separator=", " }%');

return;
}

sub timing_multivalues {
my ($this, $numcycles, $values) = @_;
my ($formTopicObject) = Foswiki::Func::readTopic($this->{test_web}, "$this->{test_topic}Form");
$formTopicObject->text(<<"HERE");
| *Name* | *Type* | *Size* | *Values* | *Tooltip* | *Attributes* |
| Topics | select+multi+values | 10 | $values | Topic | |
HERE
$formTopicObject->save();
my ($topicObject) = Foswiki::Func::readTopic($this->{test_web}, $this->{test_topic});
$topicObject->put('FORM', {name => $this->{test_web} . '.' . $this->{test_topic} . 'Form'});
$topicObject->put('FIELD', {name => 'Topics', value => $Foswiki::cfg{HomeTopicName}});
$topicObject->save();
my $benchmark = timeit(
$numcycles,
sub {
$topicObject->expandMacros(<<"HERE");
%META{"form"}%
HERE
}
);
my $timestr = timestr($benchmark);

print <<"HERE";
Timing for $numcycles cycles of %META{"form"}%
$timestr
HERE

return;
}

1;

0 comments on commit 92a3104

Please sign in to comment.