How to time a function in React Native?

Viewed 9162

This question suggests using console.time, but that isn't available in React Native. Is there a built in way to measure how long a function call takes, without using any third-party packages?

3 Answers

I ran into the same error but managed to fix it easily, just enable debugging on your app to use chrome or react native debugger. From the console of these debuggers, the console.time() and console.timeEnd() is supported and works perfectly

Using react-native v0.63 (not sure about lower versions), you can use the performance api, which is described in the question you linked in the OP.

var t0 = performance.now()
    
doSomething()   // <---- measured code goes between t0 and t1
    
var t1 = performance.now()
console.log("Call to doSomething took " + (t1 - t0) + " milliseconds.")
Related