i'm making merge sort function for arrays as a project in my computer science class and found a very interesting phenomina. i implemented both recursive and non-recursive versions and non-recursive version is much slower than recursive version. ( OS: Windows XP Pro. compiler: Microsoft Visual Studio 2005 Pro. Ed. )
excuse me for my messy source code but you can find my recursive version as MergeSort and non-recursive version as MergeSort2.
does anyone know why recursive version is faster than non-recursive version? i suspect that somehow compiler optimized well so that CPU cached function's return address and other information in register rather than in main memory but i'm not really familier with that kinda hardware related topics so... any help please.