https://github.com/d8corp/perfocode
Performance checker
https://github.com/d8corp/perfocode
Last synced: about 1 year ago
JSON representation
Performance checker
- Host: GitHub
- URL: https://github.com/d8corp/perfocode
- Owner: d8corp
- License: mit
- Created: 2020-11-02T14:44:52.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-11-15T18:00:08.000Z (over 5 years ago)
- Last Synced: 2025-03-15T06:35:44.094Z (over 1 year ago)
- Language: JavaScript
- Size: 738 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# perfocode
[](https://github.com/d8corp/perfocode/blob/master/CHANGELOG.md)
[](https://bundlephobia.com/result?p=perfocode)
[](https://www.npmjs.com/package/perfocode)
[](https://github.com/d8corp/perfocode/blob/master/LICENSE)
The simplest performance checker.
### Installation
npm
```bash
npm i perfocode -D
```
yarn
```bash
yarn add perfocode -D
```
### Using
Create `index.js` with the next code.
```javascript
const {perfocode, describe, test} = require('perfocode')
perfocode('output-file', () => {
describe('getters vs methods', () => {
class GetterVsMethod {
constructor () {
this._value = 0
}
get value () {
return this._value
}
getValue () {
return this._value
}
}
const getterVsMethod = new GetterVsMethod()
test('getter', () => getterVsMethod.value)
test('method', () => getterVsMethod.getValue())
})
})
```
Run the file.
```bash
node index.js
```
When a compare file does not exist you will see only current results.

Press `enter` if you wanna save the results to `output-file.json`.
Run the test again, and you will see the difference between the current and the previous results.

Any next running will show `min`, `max`, `previous min`, `previous max`, `current value` and `average value`.
**Average value** has **yellow** color.
Then you can see 3 numbers.
The **first** one is the **minimum** value.
The **last** one is the **maximum**. The **current** value is **colorful**.
**Gray** values are the **minimum** and the **maximum** values before.

You can modify `index.js` to change performance of getter.
```javascript
const {perfocode, describe, test} = require('perfocode')
perfocode('output-file', () => {
describe('getters vs methods', () => {
class GetterVsMethod {
constructor () {
this._value = 0
}
get value () {
for (let i = 0; i < 1000;) {
i++
}
return this._value
}
getValue () {
return this._value
}
}
const getterVsMethod = new GetterVsMethod()
test('getter', () => getterVsMethod.value)
test('method', () => getterVsMethod.getValue())
})
})
```
Run the file and you see big changes in performance.

Also, it works if you have big improvements.

You can run `describe` and `test` anywhere.
You can change testing timeout by 3rd argument of `perfocode`, `describe` and `test`
```javascript
test('empty', () => {}, 1000)
```
## Issues
If you find a bug or have a suggestion, please file an issue on [GitHub](https://github.com/d8corp/perfocode/issues)
[](https://github.com/d8corp/perfocode/issues)
> ---
[](https://github.com/d8corp/perfocode/stargazers)
[](https://github.com/d8corp/perfocode/watchers)