ROOTPLOIT
Server: Apache
System: Linux node6122.myfcloud.com 6.14.3-x86_64-linode168 #1 SMP PREEMPT_DYNAMIC Mon Apr 21 19:47:55 EDT 2025 x86_64
User: bashacomputer (1004)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/share/doc/perl-Class-Accessor/examples/benchmark
#!/usr/bin/perl -w

BEGIN {
    $ENV{MOO_XS_DISABLE} = "no cheating";
    $ENV{MOUSE_PUREPERL} = "no cheating";
}

package Bench::Base;

sub new { 
    my($class) = shift;
    bless { test => 23 }, $class;
}

package Bench::Direct;
use base qw(Bench::Base);

package Bench::Normal;
use Class::Accessor "moose-like";
has test => (is => "rw");

package Bench::Fast;
use Class::Accessor::Fast "moose-like";
has test => (is => "rw");

package Bench::Faster;
use Class::Accessor::Faster "antlers";
has test => (is => "rw");

package Bench::Moose;
use Moose;
has test => (is => "rw");

package Bench::Mouse;
use Mouse;
has test => (is => "rw");

package Bench::Moo;
use Moo;
has test => (is => "rw");

package main;
use strict;
use Benchmark 'cmpthese';
use Test::More tests => 12;

my $tmp;
my $direct = Bench::Direct->new({ test => 23 });
my %accessor = ( Direct => sub { $tmp = $direct->{test}; } );
my %mutator = ( Direct => sub { $direct->{test} = 42; } );
for my $p (qw/Normal Fast Faster Moose Mouse Moo/) {
    my $o = "Bench::$p"->new({ test => 23 });
    is $o->test, 23, "$p init";
    $o->test(24);
    is $o->test, 24, "$p set";
    $accessor{$p} = sub { $tmp = $o->test; };
    $mutator{$p}  = sub { $o->test(42); };
}

print "accessors:\n";
cmpthese( -1, \%accessor );
print "\n";
print "mutators:\n";
cmpthese( -1, \%mutator );