25

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?

Snowman
  • 31,411
  • 46
  • 180
  • 303
  • What version of RN are you using? Because I always use `console.time` and never faced any error whatsoever – Ray Sep 16 '17 at 15:43

3 Answers3

21

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 original post.

var startTime = performance.now()
    
doSomething()   // <---- measured code goes between startTime and endTime
    
var endTime = performance.now()

console.log(`Call to doSomething took ${endTime - startTime} milliseconds.`)
Tur1ng
  • 745
  • 8
  • 22
10

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

cherucole
  • 560
  • 7
  • 15
4

you can use console.time but throw third party packages react-native-console-time-polyfill
otherwise with performance monitor from developer menu Show Perf Monitor

Mohamed Khalil
  • 3,036
  • 1
  • 20
  • 26