I have a thesis going on regarding comparisons between Swift and React-Native. For the performance of both languages i compare basic algorithms such as Sieve and recursive fibonacci.
I have implemented recursive fibonacci in a react project and now I want to time the algorithm's execution time.
Here is my code so far:
const App: () => React$Node = () => {
var num = 20;
let time1;
let time2;
let executionTime;
var fibNum;
return (
<View style ={{flex: 1,
justifyContent: "center",
alignItems: "center",
margin: 8,
}}>
<Text style = {{fontSize: 24}}> {fib_run(num)} </Text>
<Text style = {{fontSize: 18}}>Time it took was {executionTime} ms</Text>
</View>
);
function fibonacci_rec(num){
if(num <= 1)
return 1;
return fibonacci_rec(num - 1) + fibonacci_rec(num - 2);
}
function fib_run(num){
time1 = new Date().getMilliseconds();
fibNum = fibonacci_rec(num);
time2 = new Date().getMilliseconds();
executionTime = (time2 - time1);
return fibNum;
}
};
For some reason the executionTime variable always shows 0. How do I solve this?
(I have very little knowledge in React-Native)
Kind regards, Stefan