#!/bin/env perl
# Test script for RT 75254
# URL: http://rt.perl.org/rt3/Public/Bug/Display.html?id=75254
# URL: http://www.perlmonks.org/?node_id=841116
use strict;
use warnings;
use Time::HiRes qw(time);
use Test::More;
use Scalar::Util qw(weaken);
# The ratio of time with weaken vs without for which we test. What is
# the performance target?
my @timefactors = reverse ( 1.5, 2, 5, 10, 25, 50, 100 );
plan tests => 5 + scalar(@timefactors);
my @data = (1, 2, 3);
pass("Begin performance test for weaken(): this may take a while.");
# Record the time without using weaken()
my $withouttime;
{
my $endtime = &withoutweaken();
my $stoptime = time;
$withouttime = $stoptime - $endtime;
}
pass(sprintf("Time without weaken(): %.2f", $withouttime));
# Record the time using weaken()
my $withtime;
{
my $endtime = &withweaken();
my $stoptime = time;
$withtime = $stoptime - $endtime;
}
pass(sprintf("Time with weaken(): %.2f", $withtime));
my $timeratio = ($withtime / $withouttime);
pass(sprintf( "Time Ratio: TIME(with) / TIME(without): %.2f", $timerat
+io ));
foreach ( @timefactors ) {
ok( $timeratio < $_, "Time ratio is < $_" );
}
pass("End performance test for weaken().");
sub withweaken {
my @h; for (1 .. 200000) {
my %hash = (data => \@data);
weaken($hash{data});
push @h, \%hash;
}
return time;
}
sub withoutweaken {
my @h; for (1 .. 200000) {
my %hash = (data => \@data);
push @h, \%hash;
}
return time;
}
|