use 5.14.2; use warnings; use Benchmark qw( cmpthese ); use Number::Latin qw( int2LATIN ); # johngg: [id://11114715] sub getColName { my ($s, $n) = ("A", @_); while ($n-- > 1) { $s++ } $s; } # getColName # tux: [id://11114673] sub col2label { my ($s, $n) = ("", @_); while ($n) { use integer; substr $s, 0, 0, chr (--$n % 26 + ord "A"); $n /= 26; } $s; } # col2label getColName (10342) eq "OGT" or die "getColName is wrong"; col2label (10342) eq "OGT" or die "col2label is wrong"; int2LATIN (10342) eq "OGT" or die "int2LATIN is wrong"; cmpthese (-4, { getcolname => sub { getColName ($_) for 1 .. 20000 }, col2label => sub { col2label ($_) for 1 .. 20000 }, int2LATIN => sub { int2LATIN ($_) for 1 .. 20000 }, });