Created
January 23, 2023 14:23
-
-
Save viktorbezdek/2052233f9501f26a66c7c9d98a42234a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _ = require("lodash/fp") | |
const sample = Array.from({ length: 90000 }).map((_, i) => i) | |
var nativeStart | |
var nativeDuration | |
;(() => { | |
nativeStart = process.hrtime.bigint() | |
for (let x = 0; x <= 10000; x++) { | |
sample.map((n) => n * 2) | |
} | |
nativeDuration = process.hrtime.bigint() - nativeStart | |
})() | |
var lodashStart | |
var lodashDuration | |
;(() => { | |
lodashStart = process.hrtime.bigint() | |
for (let y = 0; y <= 10000; y++) { | |
_.map((n) => n * 2, sample) | |
} | |
lodashDuration = process.hrtime.bigint() - lodashStart | |
})() | |
console.log(` | |
Node: ${process.version} | |
Native: ${Number(nativeDuration) / 1000000}ms | |
Lodash/fp: ${Number(lodashDuration) / 1000000}ms | |
Lodash/fp _.map can do the same thing ${( | |
(1 - 1 / (Number(nativeDuration) / Number(lodashDuration))) * | |
100 | |
).toFixed(2)}% faster than native map | |
`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment