Answer the question
In order to leave comments, you need to log in
How does recursion affect performance?
Good day.
For some time of my experience, I wrote code in a procedural style, that is, there was no talk of any recursions and functions at all (only to get rid of repetitions).
Now a task has appeared that requires maximum universalization, so I had to slightly shift my style from familiar procedures to a functional style.
How will the task execution speed change depending on nesting?
For example, there is such a situation (it is more reasonable to write in code):
function func($arg1)
{
switch(true)
{
case $arg1 == true:
Некоторые дейсвия для положительного
break;
case $arg1 == false:
Некоторые дейсвия для отрицательного
break;
default:
func(true); // если не выбрано входящее
break;
}
};
function func($arg1)
{
if(func2($arg1)!=false)
{
// некая результирующая операция, вроде закрытия файла/потока/сессии
};
};
Answer the question
In order to leave comments, you need to log in
Well the recursion yet does not mean functionality. It's all the same procedural style.
Don't worry about performance - most likely this whole section of code will not be a source of brakes, and if it is, you will see it in the profiler and then you will think about how to optimize it
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question