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% --
In reply to Re^2: Print Number With Implied Decimal Point
by Eliya
in thread Print Number With Implied Decimal Point
by j355ga
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |