ocehb: (Default)
[personal profile] ocehb


# perl -MBenchmark -de0
  DB<1> $a = "You now have a regular structure in memory, one which is very easy to deal with programmatically. To achieve your boss's first objective, which is to convert elements to attributes, you need to replace references to arrays, as shown in Listing 10."
  DB<2> sub A () { return $a =~ m#^(.{,50})\s# ? $1 : substr $a,0,50; }         
  DB<3> sub B () { my $trim = substr $a,0,50; $trim =~ s#\s+\S*?$##; return $trim; }
  DB<4> timethese (1_000_000,{ 'A' => \&A,'B' => \&B })
Benchmark: timing 1000000 iterations of A, B...
         A: -6 wallclock secs (-5.79 usr + -0.04 sys = -5.83 CPU) @ -171526.59/s (n=1000000)
            (warning: too few iterations for a reliable count)
         B:  8 wallclock secs ( 7.74 usr +  0.05 sys =  7.79 CPU) @ 128369.70/s (n=1000000)


выделение памяти под $trim?, но и под return тоже выделяется...

Date: 2007-02-07 08:17 am (UTC)
From: [identity profile] amati-fi.livejournal.com
всегда приятно поговорить с умным человеком ))

Profile

ocehb: (Default)
ocehb

January 2021

S M T W T F S
     12
345 6789
10111213141516
17181920212223
24252627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 6th, 2026 10:54 am
Powered by Dreamwidth Studios