[rt-devel] [PATCH] RT::Require faster implementation of eval "require ...".

Ruslan U. Zakirov cubic at acronis.ru
Sat Mar 27 13:13:50 EST 2004


	Hello.
Attached patch represent new function RT::Require which implement
eval "require $module". This implementation check "$module::VERSION"
before running eval.
I also wrote small perfomance test. Attached.
Results:
                      Rate     Simple eval Eval with check
Simple eval      31056/s              --            -70%
Eval with check 105263/s            239%              --

It shows that my code runs ~3 times faster when module allready loaded.

			Best regards. Ruslan.

-------------- next part --------------
#!/usr/bin/perl
use lib "/opt/rt3/lib";

use RT;
RT::LoadConfig;
RT::Init;

my $class = "RT::Ticket";
eval "require $class;";

{
	no strict qw( refs );
	*{ $class."::VERSION" } = '-1, By RT';
}

use Benchmark qw(:all);

my $count = 100000;
cmpthese($count, {
		'Simple eval' => \&simple_eval,
		'Eval with check' => \&eval_w_check
		});

sub simple_eval
{
	eval "$class";
}

sub eval_w_check
{
	no strict qw( refs );

	my $vglob = ${ $class . '::' }{'VERSION'};
	unless ( $vglob && *$vglob{'SCALAR'} ) {
		eval "require $class";
		die "Use of $class: $@" if ( $@ );
		unless ( $vglob && *$vglob{'SCALAR'} ) {
			*{ $class."::VERSION" } = '-1, By RT';
		}
	}
}

-------------- next part --------------
A non-text attachment was scrubbed...
Name: rt-require.patch
Type: application/aegis-patch
Size: 2519 bytes
Desc: not available
Url : http://pallas.eruditorum.org/pipermail/rt-devel/attachments/20040327/f8458529/rt-require.bin


More information about the Rt-devel mailing list