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 тоже выделяется...
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org

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. 5th, 2026 05:29 pm
Powered by Dreamwidth Studios