#!usr/bin/env perl use warnings; use strict; use Benchmark qw/cmpthese/; use ntheory qw/todigitstring fromdigits/; use Math::Base36 qw/encode_base36 decode_base36/; require "./mathbase.pm"; sub ntheoryA { my \$v = shift; \$v = todigitstring(fromdigits(\$v,36)+1,36) for 1..10000; \$v; } sub ntheoryB { my \$v = shift; my \$n = fromdigits(\$v,36); \$v = todigitstring(++\$n,36) for 1..10000; \$v; } sub base36A { my \$v = shift; \$v = lc encode_base36(decode_base36(\$v)+1) for 1..10000; \$v; } sub base36B { my \$v = shift; my \$n = decode_base36(\$v); \$v = lc encode_base36(++\$n) for 1..10000; \$v; } sub baseA { my \$v = shift; my \$o = Math::Base->new(36,uc \$v,1); \$v = lc ++\$o for 1..10000; \$v; } sub baseB { my \$v = shift; my \$n = Math::Base->new(36,uc \$v,1)->num; \$v = lc Math::Base->new(36,++\$n) for 1..10000; \$v; } { # Check not obviously broken. die "ntheoryA" unless ntheoryA('x000') eq 'x7ps'; die "ntheoryB" unless ntheoryB('x000') eq 'x7ps'; die "base36A" unless base36A('x000') eq 'x7ps'; die "base36B" unless base36A('x000') eq 'x7ps'; die "baseA" unless baseA('x000') eq 'x7ps'; die "baseB" unless baseB('x000') eq 'x7ps'; } cmpthese -5, { ntheory_A => sub { ntheoryA("0000"); }, ntheory_B => sub { ntheoryB("0000"); }, base36__A => sub { base36A("0000"); }, base36__B => sub { base36B("0000"); }, base____A => sub { baseA("0000"); }, base____B => sub { baseB("0000"); }, };