Updated README and nativeoverutil

Improved the examples and swapped some text with images.
This commit is contained in:
Berkmann18
2019-01-04 10:40:22 +00:00
parent ecb875c49f
commit 78c626f98f
4 changed files with 14 additions and 33 deletions

View File

@ -958,7 +958,7 @@ All statements above will return false if used with `===`
## ![✔] 7.1. Prefer native JS methods over user-land utils like Lodash ## ![✔] 7.1. Prefer native JS methods over user-land utils like Lodash
**TL;DR:** It's often more penalising to use utility libraries like `lodash` and `underscore` over native methods as it leads to unneeded dependencies and slower performance. **TL;DR:** It's often more penalising to use utility libraries like `lodash` and `underscore` over native methods as it leads to unneeded dependencies and slower performance.
Bar in mind that with the introduction of the new V8 engine alongside the new ES standards, native methods were improved in such a way that it's now about 50% more performant than utility libraries. Bear in mind that with the introduction of the new V8 engine alongside the new ES standards, native methods were improved in such a way that it's now about 50% more performant than utility libraries.
**Otherwise:** You'll have to maintain less performant projects where you could have simply used what was **already** available or dealt with a few more lines in exchange of a few more files. **Otherwise:** You'll have to maintain less performant projects where you could have simply used what was **already** available or dealt with a few more lines in exchange of a few more files.

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

View File

@ -20,50 +20,31 @@ The performance using native methods result in an overall ~50% gain which includ
<br/><br/> <br/><br/>
### Code Example Benchmark test on `_.concat`/`Array.concat` ### Example: benchmark comparison - Lodash vs V8 (Native)
The graph below shows the mean of the benchmarks for a variety of Lodash methods, this shows that Lodash methods take on average 146.23% more time to complete the same tasks as V8 methods.
![meanDiag](../../assets/images/sampleMeanDiag.png)
### Code Example Benchmark test on `_.concat`/`Array.concat`
```javascript ```javascript
const _ = require('lodash'), const _ = require('lodash'),
__ = require('underscore'), __ = require('underscore'),
Suite = require('benchmark').Suite, Suite = require('benchmark').Suite,
chalk = require('chalk'); opts = require('./utils'); //cf. https://github.com/Berkmann18/NativeVsUtils/blob/master/utils.js
function onComplete() {
let fastest = String(this.filter('fastest').map('name')),
slowest = String(this.filter('slowest').map('name'));
console.log(`\tBenchmark: ${chalk.cyan(this.name)}\nThe fastest is ${chalk.black.bgGreen(fastest)}\nThe slowest is ${chalk.black.bgRed(slowest)}\n`)
}
const onCycle = event => console.log(`${event.target}`);
const opts = {
onComplete,
onCycle
};
const concatSuite = new Suite('concat', opts); const concatSuite = new Suite('concat', opts);
const a0 = [1]; const array = [0, 1, 2];
concatSuite concatSuite.add('lodash', () => _.concat(array, 3, 4, 5))
.add('lodash', () => _.concat(a0, 2, [3], [ .add('underscore', () => __.concat(array, 3, 4, 5))
[4] .add('native', () => array.concat(3, 4, 5))
]))
.add('underscore', () => __.concat(a0, 2, [3], [
[4]
]))
.add('native', () => a0.concat(2, [3], [
[4]
]))
.run({ 'async': true }); .run({ 'async': true });
``` ```
Which returns this: Which returns this:
```bash
lodash x 1,896,368 ops/sec ±5.64% (89 runs sampled) ![output](../../assets/images/concat-benchmark.png)
underscore:
native x 2,488,685 ops/sec ±6.46% (86 runs sampled)
Benchmark: concat
The fastest is native
The slowest is lodash
```
You can find a bigger list of benchmarks [here](https://github.com/Berkmann18/NativeVsUtils/blob/master/index.txt) or alternatively [run this](https://github.com/Berkmann18/NativeVsUtils/blob/master/index.js) which would show the same but with colours. You can find a bigger list of benchmarks [here](https://github.com/Berkmann18/NativeVsUtils/blob/master/index.txt) or alternatively [run this](https://github.com/Berkmann18/NativeVsUtils/blob/master/index.js) which would show the same but with colours.
### "You don't (may not) need Lodash/Underscore" ### "You don't (may not) need Lodash/Underscore"