Front page | perl.perl5.porters |
Postings from August 2010
Re: Patch to make string-append on win32 100 times faster
Thread Previous
|
Thread Next
From:
H.Merijn Brand
Date:
August 2, 2010 04:00
Subject:
Re: Patch to make string-append on win32 100 times faster
Message ID:
20100802130023.4d7dc135@pc09.procura.nl
On Mon, 2 Aug 2010 12:36:04 +0200, demerphq <demerphq@gmail.com> wrote:
> On 31 July 2010 13:44, David Golden <xdaveg@gmail.com> wrote:
> > On Sat, Jul 31, 2010 at 1:14 AM, Eric Brine <ikegami@adaelis.com> wrote:
> >> Theres some perl way to do this without explicitly assigning a large string
> >>>
> >>
> >> It involves open(\$var)
> >
> > Sounds like a new candidate for Scalar::Util.
>
> Here are three ways to do it in perl. The first is interesting as it
> works slightly differently in that it enables the OOK flag as well,
> which IMO is a bug in substr().
Fourth way is implemented in Data::Peek
$ perl -MDP -e'DDump $_;DGrow $_, 102400; DDump $_'
SV = NULL(0x0) at 0x8301568
REFCNT = 1
FLAGS = ()
SV = PV(0x82d1114) at 0x8301568
REFCNT = 1
FLAGS = (POK,pPOK)
PV = 0x83d7558 ""\0
CUR = 0
LEN = 102400
my $LEN = DGrow ($pv, $size)
Fastest way to preallocate space for a PV scalar. Returns the allocated
length. If $size is smaller than the already allocated space, it will
not shrink.
cmpthese (-2, {
pack => q{my $x = ""; $x = pack "x20000"; $x = "";},
op_x => q{my $x = ""; $x = "x" x 20000; $x = "";},
grow => q{my $x = ""; DGrow ($x, 20000); $x = "";},
});
Rate op_x pack grow
op_x 62127/s -- -59% -96%
pack 152046/s 145% -- -91%
grow 1622943/s 2512% 967% --
XS code:
void
DGrow (sv, size)
SV *sv
IV size
PROTOTYPE: $$
PPCODE:
if (SvROK (sv))
sv = SvRV (sv);
if (!SvPOK (sv))
sv_setpvn (sv, "", 0);
SvGROW (sv, size);
mPUSHi (SvLEN (sv));
/* XS DGrow */
> Yves
>
> $ perl -MDevel::Peek -e'$size=10; $str=" " x $size;
> substr($str,0,$size,""); Dump($str); $str.="ab"; Dump($str);'
> SV = PVIV(0x8ac9fd4) at 0x8ad40c8
> REFCNT = 1
> FLAGS = (POK,OOK,pPOK)
> IV = 10 (OFFSET)
> PV = 0x8acafa2 ( " " . ) ""\0
> CUR = 0
> LEN = 2
> SV = PVIV(0x8ac9fd4) at 0x8ad40c8
> REFCNT = 1
> FLAGS = (POK,pPOK)
> IV = 0
> PV = 0x8acaf98 "ab"\0
> CUR = 2
> LEN = 12
> $ perl -MDevel::Peek -e'$size=10; $str=" " x $size; $str=~s/.+//g;
> Dump($str); $str.="ab"; Dump($str);'
> SV = PV(0x92b1748) at 0x92d10c0
> REFCNT = 1
> FLAGS = (POK,pPOK)
> PV = 0x92c7f98 ""\0
> CUR = 0
> LEN = 12
> SV = PV(0x92b1748) at 0x92d10c0
> REFCNT = 1
> FLAGS = (POK,pPOK)
> PV = 0x92c7f98 "ab"\0
> CUR = 2
> LEN = 12
> $ perl -MDevel::Peek -e'$size=10; $str=" " x $size; chop($str) while
> length($str); Dump($str); $str.="ab"; Dump($str);'
> SV = PV(0x928c748) at 0x92ac0d0
> REFCNT = 1
> FLAGS = (POK,pPOK)
> PV = 0x92a2f98 ""\0
> CUR = 0
> LEN = 12
> SV = PV(0x928c748) at 0x92ac0d0
> REFCNT = 1
> FLAGS = (POK,pPOK)
> PV = 0x92a2f98 "ab"\0
> CUR = 2
> LEN = 12
--
H.Merijn Brand http://tux.nl Perl Monger http://amsterdam.pm.org/
using 5.00307 through 5.12 and porting perl5.13.x on HP-UX 10.20, 11.00,
11.11, 11.23, and 11.31, OpenSuSE 10.3, 11.0, and 11.1, AIX 5.2 and 5.3.
http://mirrors.develooper.com/hpux/ http://www.test-smoke.org/
http://qa.perl.org http://www.goldmark.org/jeff/stupid-disclaimers/
Thread Previous
|
Thread Next