On Sun, Jun 17, 2001 at 07:04:35PM -0700, Doug MacEachern wrote:
> On Sat, 16 Jun 2001, Abhijit Menon-Sen wrote:
>
> > Consider Perl_hv_fetch (or much of hv.c), which does:
> >
> > register XPVHV* xhv;
> > ...
> > xhv = (XPVHV*)SvANY(hv);
> >
> > ... use of xhv->xhv_* ...
> >
> > In such cases (purely for reasons of grep friendliness), why not use
> > HvFOO(hv) instead? Are there compilers which don't optimise repeated
> > uses of the Hv* macros away?
>
> compilers don't optimize Hv* macros, the macros are expanded by cpp before
> the compiler sees them. there is a difference in performance, granted it
> takes quite a bit of churning to see:
So do you suggest reverting the Hv* macrofications?
> timethese(1000, {
> Hv => sub { Hv() },
> xhv => sub { xhv() }
> });
>
> Benchmark: timing 1000 iterations of Hv, xhv...
> Hv: 27 wallclock secs (27.38 usr + 0.01 sys = 27.39 CPU) @ 36.51/s (n=1000)
> xhv: 21 wallclock secs (21.02 usr + 0.00 sys = 21.02 CPU) @ 47.57/s (n=1000)
>
> int
> Hv()
>
> CODE:
> {
> U32 i;
> register HV *hv = PL_defstash;
>
> for (i=0; i<1000000; i++) {
> I32 max = HvMAX(hv);
> HE **arr = HvARRAY(hv);
> if (max && arr) {
> RETVAL = 1;
> }
> }
> }
>
> OUTPUT:
> RETVAL
>
> int
> xhv()
>
> CODE:
> {
> U32 i;
> register HV *hv = PL_defstash;
> register XPVHV *xhv = (XPVHV*)SvANY(hv);
>
> for (i=0; i<1000000; i++) {
> I32 max = xhv->xhv_max;
> HE **arr = (HE**)xhv->xhv_array;
> if (max && arr) {
> RETVAL = 1;
> }
> }
> }
>
> OUTPUT:
> RETVAL
>
--
$jhi++; # http://www.iki.fi/jhi/
# There is this special biologist word we use for 'stable'.
# It is 'dead'. -- Jack Cohen
Thread Previous
|
Thread Next