Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Print Number With Implied Decimal Point

by Eliya (Vicar)
on Apr 18, 2012 at 15:22 UTC ( #965729=note: print w/ replies, xml ) Need Help??


in reply to Re: Print Number With Implied Decimal Point
in thread Print Number With Implied Decimal Point

use bigint applied globally severely distorts the results.

As both of your test cases work on strings anyway, you'd get a more useful comparison when restricting the scope of bigint to where it's required.

With your original version, I get on my machine:

Rate substr regex substr 481/s -- -14% regex 558/s 16% --

while with the restricted scope of bigint, I get

#!/usr/bin/perl use warnings; use strict; use feature 'say'; use Benchmark qw/cmpthese/; my @list; { use bigint; my @chars = ('0' .. '9', 'a' .. 'f'); @list = map {join q(), map $chars[rand @chars], 1 .. 32} 1 .. 100; say for @list; $_ = (hex $_)."" for @list; say for @list; } cmpthese(0, { substr => sub { my @l = @list; substr $_, -2, 0, '.' for @l; }, regex => sub { my @l = @list; s/(..)$/.$1/ for @l; } }); __END__ Rate regex substr regex 5672/s -- -80% substr 28469/s 402% --


Comment on Re^2: Print Number With Implied Decimal Point
Select or Download Code
Re^3: Print Number With Implied Decimal Point
by kennethk (Monsignor) on Apr 18, 2012 at 15:38 UTC
      the timing difference between it and substr is pretty small

      Yes, sure.  My main point was the side effects of applying use bigint globally (which completely washes out any difference there might be), and not so much to support that substr is faster than regex.

Re^3: Print Number With Implied Decimal Point
by j355ga (Initiate) on Apr 19, 2012 at 14:01 UTC
    Limiting the bigint scope makes a HUGE difference in my tests. 2,100 rows per second vs 700 per sec. Thanks for the tip!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://965729]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2014-09-17 22:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (100 votes), past polls