Bring out the big-paranoia-harness - make describe_env infallible
[dbsrgits/DBIx-Class.git] / t / zzzzzzz_perl_perf_bug.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
dc253b77 3use strict;
4use warnings;
5use Test::More;
c0329273 6
ad7fbbc0 7
8BEGIN {
9 plan skip_all =>
10 'Skipping RH perl performance bug tests as DBIC_NO_WARN_BAD_PERL set'
11 if ( $ENV{DBIC_NO_WARN_BAD_PERL} );
12
13 require DBICTest::RunMode;
14 plan skip_all => 'Skipping as system appears to be a smoker'
15 if DBICTest::RunMode->is_smoker;
16}
17
db2e5392 18# globalllock so that the test runs alone
8d6b1478 19use DBICTest ':GlobalLock';
dc253b77 20
db2e5392 21use Benchmark;
22
dc253b77 23# This is a rather unusual test.
24# It does not test any aspect of DBIx::Class, but instead tests the
25# perl installation this is being run under to see if it is:-
26# 1. Potentially affected by a RH perl build bug
27# 2. If so we do a performance test for the effect of
28# that bug.
29#
30# You can skip these tests by setting the DBIC_NO_WARN_BAD_PERL env
31# variable
32#
33# If these tests fail then please read the section titled
c13fabce 34# Perl Performance Issues on Red Hat Systems in
dc253b77 35# L<DBIx::Class::Manual::Troubleshooting>
36
e7f959d8 37# we do a benchmark test filling an array with blessed/overloaded references,
38# against an array filled with array refs.
39# On a sane system the ratio between these operation sets is 1 - 1.5,
40# whereas a bugged system gives a ratio of around 8
db2e5392 41# we therefore consider there to be a problem if the ratio is >= $fail_ratio
42my $fail_ratio = 3;
43
44ok( $fail_ratio, "Testing for a blessed overload slowdown >= ${fail_ratio}x" );
45
dc253b77 46
47my $results = timethese(
db2e5392 48 -1, # run for 1 WALL second each
dc253b77 49 {
e7f959d8 50 no_bless => sub {
dc253b77 51 my %h;
e7f959d8 52 for ( my $i = 0 ; $i < 10000 ; $i++ ) {
53 $h{$i} = [];
dc253b77 54 }
55 },
e7f959d8 56 bless_overload => sub {
57 use overload q(<) => sub { };
dc253b77 58 my %h;
e7f959d8 59 for ( my $i = 0 ; $i < 10000 ; $i++ ) {
dc253b77 60 $h{$i} = bless [] => 'main';
61 }
e7f959d8 62 },
63 },
dc253b77 64);
65
e7f959d8 66my $ratio = $results->{no_bless}->iters / $results->{bless_overload}->iters;
67
db2e5392 68cmp_ok( $ratio, '<', $fail_ratio, 'Overload/bless performance acceptable' )
fc0a7ba1 69 || diag(
8622bf34 70 "\n",
fc0a7ba1 71 "This perl has a substantial slow down when handling large numbers\n",
72 "of blessed/overloaded objects. This can severely adversely affect\n",
73 "the performance of DBIx::Class programs. Please read the section\n",
74 "in the Troubleshooting POD documentation entitled\n",
75 "'Perl Performance Issues on Red Hat Systems'\n",
8622bf34 76 "As this is an extremely serious condition, the only way to skip\n",
b6883aee 77 "over this test is to --force the installation, or to look in the test\n",
8622bf34 78 "file " . __FILE__ . "\n",
fc0a7ba1 79 );
e7f959d8 80
81# We will only check for the difference in bless handling (whether the
82# bless applies to the reference or the referent) if we have seen a
83# performance issue...
84
85SKIP: {
86 skip "Not checking for bless handling as performance is OK", 1
db2e5392 87 if Test::Builder->new->is_passing;
e7f959d8 88
89 {
90 package # don't want this in PAUSE
91 TestRHBug;
92 use overload bool => sub { 0 }
93 }
94
95 sub _has_bug_34925 {
96 my %thing;
97 my $r1 = \%thing;
98 my $r2 = \%thing;
99 bless $r1 => 'TestRHBug';
100 return !!$r2;
101 }
102
103 sub _possibly_has_bad_overload_performance {
750a4ad2 104 return( "$]" < 5.008009 and !_has_bug_34925() );
e7f959d8 105 }
106
107 # If this next one fails then you almost certainly have a RH derived
108 # perl with the performance bug
109 # if this test fails, look at the section titled
110 # "Perl Performance Issues on Red Hat Systems" in
111 # L<DBIx::Class::Manual::Troubleshooting>
112 # Basically you may suffer severe performance issues when running
113 # DBIx::Class (and many other) modules. Look at getting a fixed
114 # version of the perl interpreter for your system.
115 #
116 ok( !_possibly_has_bad_overload_performance(),
fc0a7ba1 117 'Checking whether bless applies to reference not object' )
118 || diag(
8622bf34 119 "\n",
fc0a7ba1 120 "This perl is probably derived from a buggy Red Hat perl build\n",
121 "Please read the section in the Troubleshooting POD documentation\n",
122 "entitled 'Perl Performance Issues on Red Hat Systems'\n",
8622bf34 123 "As this is an extremely serious condition, the only way to skip\n",
b6883aee 124 "over this test is to --force the installation, or to look in the test\n",
8622bf34 125 "file " . __FILE__ . "\n",
fc0a7ba1 126 );
e7f959d8 127}
db2e5392 128
129done_testing;