Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all articles
Browse latest Browse all 1877

New Post: Bijective base-26

$
0
0
First time I see p-adic numbers being used outside pure mathematics =)

Ran some tests and the results are...

XLHelper.GetColumnLetterFromNumber is slightly better than ToBijectiveBase26.
FromBijectiveBase26 is slightly better than XLHelper.GetColumnNumberFromLetter.

In this case "slightly better" really means "it doesn't matter" because the difference is a whooping 1 second (if that) for every 10 million operations.

Each test ran 10M times.

ToBijectiveBase26:

Test 1 random column (1-26)
Took: 2.2978524 secs

Test 2 random columns (27-702)
Took: 2.9170196 secs

Test 3 random columns (703-16384)
Took: 3.6836017 secs

XLHelper.GetColumnLetterFromNumber:

Test 1 random column (1-26)
Took: 0.8154559 secs

Test 2 random columns (27-702)
Took: 1.2372901 secs

Test 3 random columns (703-16384)
Took: 1.8447462 secs



FromBijectiveBase26:

Test 1 random column (A-Z)
Took: 0.3456822 secs

Test 2 random columns (AA-ZZ)
Took: 0.5361384 secs

Test 3 random columns (AAA-XFD)
Took: 1.1249966 secs

XLHelper.GetColumnNumberFromLetter

Test 1 random column (A-Z)
Took: 1.3690976 secs

Test 2 random columns (AA-ZZ)
Took: 1.5478759 secs

Test 3 random columns (AAA-XFD)
Took: 1.488285 secs


I rewrote your ToBijectiveBase26 function to be more performant:
        public static String ToBijectiveBase26(Int32 n)
        {
            var ret = String.Empty;
            while (n > 0)
            {
                --n;
                ret = (char)('A' + n % 26) + ret;
                n /= 26;
            }
            return ret;
        }
(This stupid editor keeps replacing the plus sign with +)

NEW ToBijectiveBase26:

Test 1 column (1-26)
Took: 0.7168028 secs

Test 2 columns (27-702)
Took: 1.1513819 secs

Test 3 columns (703-16384)
Took: 1.7939328 secs


In the interest of having "the best" we'll use FromBijectiveBase26 and the new ToBijectiveBase26.

Thanks!

Viewing all articles
Browse latest Browse all 1877

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>