Answer the question
In order to leave comments, you need to log in
How to calculate the execution time of a function without directly executing the same function?
There is a function with the calculation of the Fibonacci number by recursion.
int fib(n) {
if (n<= 2) return 1
else return fib(n-1) + fib(n-2);
}
Answer the question
In order to leave comments, you need to log in
Time without direct execution is essentially nothing. Only complexity. Of course, you can translate it into assembler, calculate the number of operations, accept that 1 operation is performed in 1 cycle (which is also a very rough assumption) and then, knowing the processor frequency, get the time. But it will all be very approximate. And in practice, the execution time of the function will always be longer, and how much depends on many parameters. Do not forget other optimizations, other higher priority things in the OS and processes, etc.
Time - no way: it is not known on what machine, it is not known on what OS, it is not known in what language.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question