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 | |
by Eliya (Vicar) on Apr 18, 2012 at 15:46 UTC | |
|
Re^3: Print Number With Implied Decimal Point
by j355ga (Initiate) on Apr 19, 2012 at 14:01 UTC |