Skip to content

Commit

Permalink
Item11332: Sync trivial changes from trunk
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/branches/Release01x01@13330 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
PaulHarvey authored and PaulHarvey committed Dec 8, 2011
1 parent 95710ad commit c3ecbfa
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 17 deletions.
8 changes: 2 additions & 6 deletions UnitTestContrib/test/unit/AccessControlTests.pm
Expand Up @@ -736,12 +736,8 @@ THIS
# ShortURLs may involve a {ScriptUrlPaths}{view} of '' or something
# like '/foswiki' (where {ScriptUrlPath} looks like '/foswiki/bin').
# In any case, the test is hard-wired to ignore {ScriptSuffix}
if ( exists $Foswiki::cfg{ScriptUrlPaths}{view}
and defined $Foswiki::cfg{ScriptUrlPaths}{view}
and not $Foswiki::cfg{ScriptUrlPaths}{view} =~ /view$/ )
{
$this->expect_failure();
}
$this->expect_failure(
'Test does\'t cater to ShortURL configurations', using => 'ShortURLs');

# Extract what we've been redirected to
my ($redirect_to) = $text =~ /^Location: (.*?)\r?$/m;
Expand Down
4 changes: 2 additions & 2 deletions UnitTestContrib/test/unit/CacheTests.pm
Expand Up @@ -151,8 +151,8 @@ sub verify_view {
);
$this->assert( s/([?;&]t=)\d+/${1}0/g,
'Failed to replace timestamp in page URL with dummy (0)' );
# Do *not* assert the removal of SERVERTIME; it is only present
# if the JQueryPlugin::FOSWIKI plugin is installed and enabled.
# Do *not* assert the removal of SERVERTIME; it is only present
# if the JQueryPlugin::FOSWIKI plugin is installed and enabled.
s/<meta[^>]*?foswiki\.SERVERTIME"[^>]*?>//gi;

# There may not be TWISTY usage; so no need to assert, but IDs need
Expand Down
2 changes: 1 addition & 1 deletion UnitTestContrib/test/unit/FoswikiFnTestCase.pm
Expand Up @@ -62,7 +62,7 @@ to add extra stuff to Foswiki::cfg.
sub loadExtraConfig {
my $this = shift;
$this->SUPER::loadExtraConfig(@_);

$Foswiki::cfg{Store}{Implementation} = "Foswiki::Store::RcsLite";
$Foswiki::cfg{RCS}{AutoAttachPubFiles} = 0;
$Foswiki::cfg{Register}{AllowLoginName} = 1;
Expand Down
65 changes: 63 additions & 2 deletions UnitTestContrib/test/unit/RenderFormTests.pm
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 All @@ -18,7 +19,6 @@ BEGIN {
$codedir = File::Temp::tempdir( CLEANUP => 1 );
mkdir("$codedir/Foswiki") || die $!;
mkdir("$codedir/Foswiki/Form") || die $!;
open( my $F, '>', "$codedir/Foswiki/Form/Nuffin.pm" ) || die $!;

my $code = <<'CODE';
package Foswiki::Form::Nuffin;
Expand All @@ -35,6 +35,8 @@ sub renderForDisplay {
1;
CODE

open( my $F, '>', "$codedir/Foswiki/Form/Nuffin.pm" ) || die $!;
print $F $code;
close($F) || die $!;
push( @INC, $codedir );
Expand Down Expand Up @@ -427,7 +429,7 @@ sub test_nondefined_form {
my $web = $this->{test_web};
my $topic = 'FormDoesntExist';

my $rawtext = <<TOPIC;
my $rawtext = <<'TOPIC';
%META:FORM{name="NonExistantPluginTestForm"}%
%META:FIELD{name="ExtensionName" attributes="" title="ExtensionName" value="Example"}%
%META:FIELD{name="TopicClassification" attributes="" title="TopicClassification" value="SkinPackage"}%
Expand Down Expand Up @@ -497,4 +499,63 @@ 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;
2 changes: 1 addition & 1 deletion UnitTestContrib/test/unit/UIFnCompileTests.pm
Expand Up @@ -65,7 +65,7 @@ sub fixture_groups {
context => $array[2],
};
}

next unless (ref($dispatcher) eq 'HASH');#bad switchboard entry.

my $package = $dispatcher->{package} || 'Foswiki::UI';
Expand Down
137 changes: 133 additions & 4 deletions UnitTestContrib/test/unit/UTF8Tests.pm
Expand Up @@ -11,12 +11,16 @@
# to have to work out how to re-initialise Foswiki for each test)
#
package UTF8Tests;
use FoswikiFnTestCase;
our @ISA = qw( FoswikiFnTestCase );

use strict;
use warnings;
use utf8;

use Foswiki;
use Unicode::UCD();
use Benchmark qw( :hireswallclock);
use FoswikiFnTestCase();
our @ISA = qw( FoswikiFnTestCase );

use Foswiki();

sub DISABLEtest_urlEncodeDecode {
my $this = shift;
Expand Down Expand Up @@ -325,4 +329,129 @@ sub segfaulting_urlDecode {
return $text;
}

=begin TML
On my Debian wheezy perl 5.14 environment the results are:
UTF8Tests::test_timing_maths_int_UCD
Timing += Unicode::UCD::num(n)
0.0964899 wallclock secs ( 0.10 usr + 0.00 sys = 0.10 CPU) @ 120000.00/s (n=12000)
UTF8Tests::test_timing_maths_int
Timing += n
0.089103 wallclock secs ( 0.09 usr + 0.00 sys = 0.09 CPU) @ 7222222.22/s (n=650000)
UTF8Tests::test_timing_maths_real_UCD
Timing =~ /([\d+.-])/; += Unicode::UCD::num(..)
0.10401 wallclock secs ( 0.10 usr + 0.00 sys = 0.10 CPU) @ 50000.00/s (n=5000)
UTF8Tests::test_timing_maths_real
Timing += n.1
0.116107 wallclock secs ( 0.11 usr + 0.00 sys = 0.11 CPU) @ 4545454.55/s (n=500000)
So, for an outrageously trivial loop, adding:
* pos.ints with UCD is ~ 60 times slower than without
* realnums with UCD is ~ 90 times slower than without, but the test is
probably disadvantaging UCD with an inefficient implementation
=cut

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

if ( defined &Unicode::UCD::num ) {
my $numcycles = 5000;
my $rev = 0;
my @numbers = map { $_ + 0.1 } ( 0 .. $numcycles );
my $benchmark = timeit(
$numcycles,
sub {
pop(@numbers) =~ /^(|-)?(\d+)(\.(\d+))?$/;
my $num = $1 . Unicode::UCD::num($2);

if ( defined $4 ) {
$num .= '.' . Unicode::UCD::num($4);
}
$rev += $num;
}
);

print "Timing =~ /([\\d+\.-])/; += Unicode::UCD::num(..)\n\t"
. timestr($benchmark) . "\n";
}
else {
print STDERR
"SKIPPED test_timing_maths_int_UCD_regex, you need a newer Unicode::UCD (or perl >= 5.14)\n";
}

return;
}

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

if ( defined &Unicode::UCD::num ) {
my $numcycles = 500000;
my $rev = 0;
my @numbers = map { $_ + 0.1 } ( 0 .. $numcycles );
my $benchmark = timeit(
$numcycles,
sub {
$rev += pop(@numbers);
}
);

print "Timing += n.1\n\t" . timestr($benchmark) . "\n";
}
else {
print STDERR
"SKIPPED test_timing_maths_real, you need a newer Unicode::UCD (or perl >= 5.14)\n";
}

return;
}

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

if ( defined &Unicode::UCD::num ) {
my $numcycles = 12000;
my $rev = 0;
my @numbers = ( 0 .. $numcycles );
my $benchmark = timeit(
$numcycles,
sub {
$rev += Unicode::UCD::num( pop(@numbers) );
}
);

print "Timing += Unicode::UCD::num(n)\n\t" . timestr($benchmark) . "\n";
}
else {
print STDERR
"SKIPPED test_timing_maths_int_UCD, you need a newer Unicode::UCD (or perl >= 5.14)\n";
}

return;
}

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

if ( defined &Unicode::UCD::num ) {
my $numcycles = 650000;
my $rev = 0;
my @numbers = ( 0 .. $numcycles );
my $benchmark = timeit(
$numcycles,
sub {
$rev += pop(@numbers);
}
);

print "Timing += n\n\t" . timestr($benchmark) . "\n";
}
else {
print STDERR
"SKIPPED test_timing_maths_int, you need a newer Unicode::UCD (or perl >= 5.14)\n";
}

return;
}

1;
1;
2 changes: 1 addition & 1 deletion UnitTestContrib/test/unit/ViewScriptTests.pm
Expand Up @@ -33,7 +33,7 @@ NotTOAutoLink
HERE

#Sven is curious why the comment="" is in the meta - I thought that was dead and buried.
my $topic2meta = '%META:TOPICINFO{author="BaseUserMapping_666"( comment="")? date="[0-9]{10,10}" format="1.1" version="1"}%\n';
my $topic2meta = '%META:TOPICINFO{author="BaseUserMapping_666"( comment="")? date="[0-9]{10,10}" format="1.1" version="1"}%\n';
my $topic2metaQ = $topic2meta;
$topic2metaQ =~ s/"/&quot;/g;

Expand Down

0 comments on commit c3ecbfa

Please sign in to comment.