Need some help writing a recursive function

btw, using this calling code, you can see that my recursive function is WAYYYYYYY FASTER!!! as much as 2x fast on large column indexes (albeit ms…lol eyeroll)…I am vindicated !!!

$stopwatch = [System.Diagnostics.Stopwatch]::new()
$txt = myfunction 100000
write-host "Recursive function took", $Stopwatch.Elapsed.Milliseconds, "ms"
write-host $txt

Get-ExcelColumnName 100000
write-host "Get-ExcelColumnName took", $Stopwatch.Elapsed.Milliseconds, "ms"

Great. Congrats … You may add the results you’ve got on your machine for those who does not have the ImportExcel module installed. :wink: (if you do, please add them to the same post - do not add a new one. Thanks in advance)

How many Excel sheets with 100,000 or more columns do you usually have to process? :wink: :wink: :crazy_face:

And just BTW: the ImportExcel module is not made by MS. Doug Finke is the developer.

Not to piss on your fireworks but I think your testing is flawed :slight_smile: :fireworks:

Using your code but just reversing the order of execution, I found that if you test Get-ExcelColumnName before myfunction it’s twice as fast as myfunction.

It looks like this has something to do with the stopwatch. If you create a new instance of the stopwatch say:

$stopwatch2 = [System.Diagnostics.Stopwatch]::new()
Get-ExcelColumnName 100000
write-host "Get-ExcelColumnName took", $Stopwatch2.Elapsed.Milliseconds, "ms"

the timings are mostly identical.

Likewise, with Measure-Command, both your function and Get-ExcelColumnName take a similar amount of time.

PS E:\Temp> (Measure-Command {myfunction 10000}).TotalMilliseconds
PS E:\Temp> (Measure-Command {Get-ExcelColumnName 10000}).TotalMilliseconds

Lies! all Lies!..Recursion Rules!

well, if it is just as fast, then i will take that as a win.