Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/MaxGraey/react-native-console-time-polyfill

console.time and console.timeEnd polyfill for react-native
https://github.com/MaxGraey/react-native-console-time-polyfill

console measurements performance polyfill react-native time

Last synced: 5 days ago
JSON representation

console.time and console.timeEnd polyfill for react-native

Awesome Lists containing this project

README

        

## react-native-console-time-polyfill

Starts a timer you can use to track how long an operation takes. When you call ***console.timeEnd()/console.timeLog()*** with the same name, the react-native will output the time, in milliseconds, that elapsed since the timer was started.

Also you can use ***console.count()*** and ***console.countReset()*** for determine number of function calls.

### Installation

Install library from **npm**

```bash
npm install --save react-native-console-time-polyfill
```

or **yarn**

```bash
yarn add react-native-console-time-polyfill
```

### Syntax

```javascript
console.time(label);
console.timeLog(label);
console.timeEnd(label);

console.count(label);
console.countReset(label);
```

### Parameters

***label***

The name to give the new timer or counter. This will identify the timer or counter.

Use the same name when calling ***console.timeEnd()*** to stop the timer and get the time output to the console.

### Usage

Use the following code:

```javascript
// in your root javascript / typescript file
import 'react-native-console-time-polyfill'

// now you can use polyfill in your components
export default function SomeComponent({ children, ...props }) => {
useEffect(() => { // or useLayoutEffect
console.time('SomeComponent(init) time')
// "some slow initialization code"
console.timeEnd('SomeComponent(init) time')

return () => {
console.countReset('SomeComponent(render) calls')
}
}, [])

useEffect(() => {
console.count('SomeComponent(render) calls')
})

return { children }
}
```

### Output

```
SomeComponent(init) time: 200ms
SomeComponent(render) calls: 2
```