Part Ten - Performance Measures

Nested C++ Recursion - Introduction (Main Article Page)

Part Nine - Memory Consumption showed how to measure memory consumption of recursive C++ software, focusing on the C++ software described in this article. Part Ten here will compare the performance of the recursive solutions described in this article.

Although recursion becomes a powerful tool that solves otherwise impossible problems, it has its tradeoffs: slow speed and huge memory demands. This table shows speed and stack use test results for the solution versions described in this article, all available for download at this GitHub resource. The testing took place on the hardware / software environment described earlier.




These screenshots show the speed and stack use of the recursive solutions that measure stack resource use:






Compared to the loop solution, the array lambda solutions can run almost seven times slower. They can have almost six times bigger default stack reserve requirements. The vector solutions do even worse. The loop solution can handle a zero-MB Stack Size Reserve setting:



However, if recursion becomes the only technique that will solve a problem, we can accept the trade-off.

_________________________
________________________________________________________
_________________________

This article showed that

   • anonymous functions
   • closures
   • lambdas

will support C++ recursive solution engineering. Although tail-end recursion and memoization can boost recursion speed and efficiency, we should avoid recursion whenever possible because of its resource and time demands. However, when recursion becomes the only option available, this ten part article shows how to proceed.