On Tue, Dec 19, 2000 at 06:11:06PM +0000, David Mitchell wrote:
> Since in real life the types of args are often the same, this will usually
> be a win.

I found that you have to make an effort to make them the same, else generally
enough of them aren't that decision making code outweighs speed gains.
This is in the context of making the maths operators in perl use integers
if possible, which increases the choice from NV (eg double) to NV or IV or UV
(double or long or unsigned long, typically)

With no special effort, you get UVs and IVs about half the time, and a
high chance of hitting the mixed case. So much so that 2 if statements:

void
Perl_sv_setuv(pTHX_ register SV *sv, UV u)
{
    if (u <= (UV)IV_MAX) {
       sv_setiv(sv, (IV)u);
       return;
    }
    sv_setiv(sv, 0);
    SvIsUV_on(sv);
    SvUVX(sv) = u;
}

void
Perl_sv_setuv_mg(pTHX_ register SV *sv, UV u)
{
    if (u <= (UV)IV_MAX) {
       sv_setiv(sv, (IV)u);
    } else {
       sv_setiv(sv, 0);
       SvIsUV_on(sv);
       sv_setuv(sv,u);
    }
    SvSETMAGIC(sv);
}


to force IV whenever possible take the performance of perl5.7 from:

u=1.35  s=0.47  cu=73.45  cs=11.43  scripts=270  tests=20865

real    2m17.827s
user    1m14.800s
sys     0m11.900s

up slightly (user+sys) to

u=1.49  s=0.52  cu=72.49  cs=10.64  scripts=270  tests=20865

real    2m25.145s
user    1m13.980s
sys     0m11.160s

which reminds me to submit a patch to Jarkko of a comment next to those
two if statements to show their importance (and "benchmark if you change
this")


> So, should I have the courage of my convictions and let rip, or should I
> just leave this to wiser people? Answers on a postcard, please....

You appear to have a logical way of thinking, and you probably know more
about parsers than I do. (I know nothing, so I try to keep quiet)

Nicholas Clark

Reply via email to