E
E
eatmypants2014-09-22 10:32:54
JavaScript
eatmypants, 2014-09-22 10:32:54

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);
}

It is necessary to calculate the approximate execution time of this function, if for example n = 100.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alex Glebov, 2016-09-21
@letehaha

https://jsfiddle.net/x9zq4byk/1/

G
GavriKos, 2014-09-22
@eatmypants

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.

D
DancingOnWater, 2014-09-22
@DancingOnWater

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 question

Ask a Question

731 491 924 answers to any question