Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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% --

Replies are listed 'Best First'.
Re^3: Print Number With Implied Decimal Point
by kennethk (Abbot) 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://965729]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2017-10-20 15:15 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (263 votes). Check out past polls.