[ic] Performance effects of using $Tag in usertag

Mike Heins mike at perusion.com
Thu Apr 7 16:16:29 EDT 2005


Quoting JT Justman (jt at airdelights.com):
> Hello, everyone. Sorry if this has been covered - the search doesn't
> differentiate between 'tag' and '$Tag' and so I got lots of general
> performance ideas, but nothing specifically on $Tag.
> 
> I'm writing two usertags that will be used very often - 10+ times on
> every page. I want to have two different tags which are very similar and
> a reasonable way to do that would be to call one tag from the other. My
> question is, though, is there a lot of overhead associated with $Tag
> calls? Would I be better served to re-use my code in a different way?

Not a great deal of overhead -- we use $Tag all the time with what we
think is excellent performance. But I guess I didn't really know, so
I just benchmarked it with this:

UserTag tag1 Order number
UserTag tag1 addAttr
UserTag tag1 Routine <<EOR
sub {
        my ($number, $opt) = @_;
	use vars qw/$Tag/;
	$number ||= 10000;
        my @out;
        $Tag->benchmark({start => 1});

        if($opt->{nohash}) {
            for(1 .. $number) {
                    $Tag->tag2($_);
            }
        }
        else {
            for(1 .. $number) {
                    $Tag->tag2({ number => $_ });
            }
        }

        return "$number in " . $Tag->benchmark({display => 1});
}
EOR

UserTag tag2 Order number
UserTag tag2 Routine <<EOR
sub {
        my $number = shift;
        return $number;
}
EOR

That yielded an apparent overhead of about 12 microseconds per
tag call on my system (a fairly fast desktop workstation), i.e.
1000 calls took .012 seconds -- with the hash-style arguments.

This page call:

    nohash=[tag1 number=100000 nohash=1]<br>
    hash=[tag1 number=100000]

Yielded:

    nohash=100000 in 0.600
    hash=100000 in 1.220

Obviously you can cut down overhead by not using the hash-style
parameters, but they are convenient.

-- 
Mike Heins
Perusion -- Expert Interchange Consulting    http://www.perusion.com/
phone +1.765.647.1295  tollfree 800-949-1889 <mike at perusion.com>

Fast, reliable, cheap.  Pick two and we'll talk.  -- unknown


More information about the interchange-users mailing list