Add true/false non-singleton boolean objects
[dbsrgits/DBIx-Class.git] / t / zzzzzzz_perl_perf_bug.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
3 use strict;
4 use warnings;
5 use Test::More;
6
7
8 BEGIN {
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
18 # globalllock so that the test runs alone
19 use DBICTest ':GlobalLock';
20
21 use Benchmark;
22
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
34 # Perl Performance Issues on Red Hat Systems in
35 # L<DBIx::Class::Manual::Troubleshooting>
36
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
41 # we therefore consider there to be a problem if the ratio is >= $fail_ratio
42 my $fail_ratio = 3;
43
44 ok( $fail_ratio, "Testing for a blessed overload slowdown >= ${fail_ratio}x" );
45
46
47 my $results = timethese(
48     -1,    # run for 1 WALL second each
49     {
50         no_bless => sub {
51             my %h;
52             for ( my $i = 0 ; $i < 10000 ; $i++ ) {
53                 $h{$i} = [];
54             }
55         },
56         bless_overload => sub {
57             use overload q(<) => sub { };
58             my %h;
59             for ( my $i = 0 ; $i < 10000 ; $i++ ) {
60                 $h{$i} = bless [] => 'main';
61             }
62         },
63     },
64 );
65
66 my $ratio = $results->{no_bless}->iters / $results->{bless_overload}->iters;
67
68 cmp_ok( $ratio, '<', $fail_ratio, 'Overload/bless performance acceptable' )
69   || diag(
70     "\n",
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",
76     "As this is an extremely serious condition, the only way to skip\n",
77     "over this test is to --force the installation, or to look in the test\n",
78     "file " . __FILE__ . "\n",
79   );
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
85 SKIP: {
86     skip "Not checking for bless handling as performance is OK", 1
87       if Test::Builder->new->is_passing;
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 {
104         return( "$]" < 5.008009 and !_has_bug_34925() );
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(),
117         'Checking whether bless applies to reference not object' )
118       || diag(
119         "\n",
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",
123         "As this is an extremely serious condition, the only way to skip\n",
124         "over this test is to --force the installation, or to look in the test\n",
125         "file " . __FILE__ . "\n",
126       );
127 }
128
129 done_testing;