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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Take into account that there is a real performance difference between the three methods, which especially shows for high column numbers:

(warning: too few iterations for a reliable count) Rate getcolname int2LATIN col2label getcolname 0.119/s -- -100% -100% int2LATIN 31.4/s 26218% -- -55% col2label 68.9/s 57742% 120% --

So if this is hot code, don't use johngg's version, however nice his solution is :)

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 }, });

Enjoy, Have FUN! H.Merijn

In reply to Re^3: Get Excel column name for given decimal number by Tux
in thread Get Excel column name for given decimal number by Akshit

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2023-03-31 08:44 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (75 votes). Check out past polls.