in reply to Access via substr refs 2000 times slower
You're triggering substr's lvalue return, which involves magic.
use Devel::Peek; { my $subRef = \substr $string, 0; Dump($$subRef); } { my $subRef = \(''.substr $string, 0); Dump($$subRef); }
SV = PVLV(0x1834fdc) at 0x1831820 REFCNT = 2 FLAGS = (PADMY,GMG,SMG,pPOK) IV = 0 NV = 0 PV = 0x18208ec ""\0 CUR = 0 LEN = 4 MAGIC = 0x182443c MG_VIRTUAL = &PL_vtbl_substr MG_TYPE = PERL_MAGIC_substr(x) TYPE = x TARGOFF = 0 TARGLEN = 0 TARG = 0x236dc8 SV = PV(0x238e44) at 0x236dc8 REFCNT = 2 FLAGS = (POK,pPOK) PV = 0x182eca4 ""\0 CUR = 0 LEN = 4 SV = PV(0x238e80) at 0x1831808 REFCNT = 2 FLAGS = (PADBUSY,PADMY,POK,pPOK) PV = 0x183646c ""\0 CUR = 0 LEN = 4
By changing to
my $subRef = \(''.substr $string, 0);
I get
0.0120670795440674 0.0105710029602051 0.010854959487915
Update: scalar also works, and doesn't have the (albeit minute) overhead of calling concat.
my $subRef = \scalar substr $string, 0;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Access via substr refs 2000 times slower
by BrowserUk (Patriarch) on Dec 28, 2008 at 11:53 UTC | |
by ikegami (Patriarch) on Dec 28, 2008 at 13:15 UTC | |
by tilly (Archbishop) on Dec 28, 2008 at 18:58 UTC | |
by BrowserUk (Patriarch) on Dec 28, 2008 at 21:39 UTC | |
by ikegami (Patriarch) on Dec 29, 2008 at 00:29 UTC |