Last 12 weeks · 0 commits
4 of 6 standards met
Fixes https://github.com/sindresorhus/is-plain-obj/issues/12 This improves the performance. Benchmarks on Node 18.3.0 on my machine, before the change: After the change: In a nutshell: Some less-used native types (, ) are 60 times faster Most native types (, , , , ) and functions are 5 times faster Plain objects are 50% times faster. This is important since they are the most likely argument. Class instances and many core object types (, , , , , ) are 2-4 times faster is 30% faster is 10% slower , , , are 30% slower. This is the main drawback. However, this seems worthwhile based on the other improvements. is twice slower. It is rarely used though.
I believe the following code: Should behave the same as the following one: This is because the only case where: is for objects which inherit from . However, for those, . Benchmarks This second code seems to be much faster on my machine (Node 18.3.0): Results (first time is current code, second time is new code, left value is input): : 1s vs 1.5s , : 430ms vs 240ms : 530ms vs 200ms : 600ms vs 245ms : 580ms vs 240ms : 600ms vs 1s then : 3s vs 1s : 4s vs 1s So, overall, the new code performs roughly 33% faster on plain objects, 50-60% faster with native types, and up to 75% faster with non-plain objects (except for ).
Repository: sindresorhus/is-plain-obj. Description: Check if a value is a plain object Stars: 104, Forks: 9. Primary language: JavaScript. Languages: JavaScript (89.4%), TypeScript (10.6%). License: MIT. Latest release: v4.1.0 (4y ago). Open PRs: 0, open issues: 0. Last activity: 2y ago. Community health: 85%. Top contributors: sindresorhus, ehmicky, coreyfarrell, BendingBender, schnittstabil, rocktimsaikia, fisker.