-
-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Benchmark result #5
Comments
yes, true. But not that slow, and unfortunately it's necessary to be able to get non-enumerable prototype methods.
we can't remove that feature because it's used extensively in a number of projects. It allows you to dynamically create keys without having to slice/concat args then var obj = {a: {b: {c: 'd'}}};
get(obj, ['a', 'b', 'c']);
// is the equivalent of
get(obj, 'a.b.c'); So, for example, let's say you want to create a custom function Views() {
this.views = {};
}
Views.prototype.set = function(key) {
set(this, key, val);
return this;
};
Views.prototype.get = function(key) {
return get(this, key);
};
Views.prototype.getView = function(key) {
// ignore the fact that we can just use `get(this.views,..)` for a moment
// this allows us to not have to join `views` to `?`, which would need to
// be split again later
return this.get(['views', key]);
}; Of course, in this example you could easily just use get directly and do Plus, in the benchmarks that code does not have much of an impact on speed, since it's explicit. hope that makes sense. |
I see. That's the reason why this lib is slower than I understand the feature but never considered that use case. |
Interesting, I get 2.8m ops/sec for this lib versus 3m ops/sec for dot prop. what version of node are you running?
good idea. closing this, but I'll open a new one for docs |
I'm using Node 5.1. On Fri, Jan 22, 2016 at 12:50 PM, Jon Schlinkert notifications@github.com
|
$ node -v; npm -v
v5.1.0
3.5.0
$ npm ls --depth 0
get-value@2.0.3
├── ansi-bold@0.1.1
├── arr-reduce@1.0.1
├── benchmarked@0.1.4
├── dot-prop@2.2.0
├── getobject@0.1.0
├── gulp@3.9.0
├── gulp-eslint@1.1.1
├── gulp-format-md@0.1.5
├── gulp-istanbul@0.10.3
├── gulp-mocha@2.2.0
├── isobject@2.0.0
├── matched@0.3.2
├── minimist@1.2.0
├── mocha@2.3.4
└── should@8.1.1
# master
$ node benchmark
#1: deep
current x 2,664,756 ops/sec ±0.56% (98 runs sampled)
dot-prop x 3,796,504 ops/sec ±0.47% (97 runs sampled)
getobject x 261,985 ops/sec ±0.30% (99 runs sampled)
fastest is dot-prop
#2: shallow-long
current x 4,119,104 ops/sec ±0.39% (97 runs sampled)
dot-prop x 6,463,488 ops/sec ±0.28% (95 runs sampled)
getobject x 840,169 ops/sec ±0.52% (95 runs sampled)
fastest is dot-prop
#3: shallow
current x 4,080,770 ops/sec ±0.20% (98 runs sampled)
dot-prop x 6,287,998 ops/sec ±0.54% (95 runs sampled)
getobject x 727,382 ops/sec ±1.18% (90 runs sampled)
fastest is dot-prop
# commented `prop in obj`
$ node benchmark
#1: deep
current x 3,452,616 ops/sec ±0.47% (96 runs sampled)
dot-prop x 3,681,697 ops/sec ±0.52% (96 runs sampled)
getobject x 270,249 ops/sec ±0.51% (99 runs sampled)
fastest is dot-prop
#2: shallow-long
current x 5,696,825 ops/sec ±0.52% (96 runs sampled)
dot-prop x 6,433,232 ops/sec ±0.42% (93 runs sampled)
getobject x 869,137 ops/sec ±0.56% (96 runs sampled)
fastest is dot-prop
#3: shallow
current x 5,616,723 ops/sec ±0.37% (99 runs sampled)
dot-prop x 6,444,482 ops/sec ±0.67% (96 runs sampled)
getobject x 924,384 ops/sec ±1.11% (93 runs sampled)
fastest is dot-prop |
$ node -v; npm -v
v4.1.1
2.14.4
$ npm ls --depth 0
get-value@2.0.3
├── ansi-bold@0.1.1
├── arr-reduce@1.0.1
├── benchmarked@0.1.4
├── dot-prop@2.2.0
├── getobject@0.1.0
├── gulp@3.9.0
├── gulp-eslint@1.1.1
├── gulp-format-md@0.1.5
├── gulp-istanbul@0.10.3
├── gulp-mocha@2.2.0
├── isobject@2.0.0
├── matched@0.3.2
├── minimist@1.2.0
├── mocha@2.3.4
└── should@8.1.1
# master
$ node benchmark
#1: deep
current x 2,569,185 ops/sec ±0.38% (97 runs sampled)
dot-prop x 3,583,916 ops/sec ±0.33% (99 runs sampled)
getobject x 273,026 ops/sec ±0.16% (99 runs sampled)
fastest is dot-prop
#2: shallow-long
current x 3,950,008 ops/sec ±0.60% (92 runs sampled)
dot-prop x 6,304,140 ops/sec ±0.32% (96 runs sampled)
getobject x 863,239 ops/sec ±0.36% (98 runs sampled)
fastest is dot-prop
#3: shallow
current x 3,842,925 ops/sec ±0.14% (100 runs sampled)
dot-prop x 6,284,504 ops/sec ±0.42% (100 runs sampled)
getobject x 918,652 ops/sec ±0.30% (99 runs sampled)
fastest is dot-prop
# commented `prop in obj`
$ node benchmark
#1: deep
current x 3,213,149 ops/sec ±0.45% (96 runs sampled)
dot-prop x 3,587,530 ops/sec ±0.55% (96 runs sampled)
getobject x 273,838 ops/sec ±0.36% (100 runs sampled)
fastest is dot-prop
#2: shallow-long
current x 5,369,434 ops/sec ±0.38% (96 runs sampled)
dot-prop x 5,904,589 ops/sec ±0.31% (97 runs sampled)
getobject x 873,513 ops/sec ±0.66% (94 runs sampled)
fastest is dot-prop
#3: shallow
current x 5,412,105 ops/sec ±0.26% (91 runs sampled)
dot-prop x 6,230,873 ops/sec ±0.76% (96 runs sampled)
getobject x 890,037 ops/sec ±0.38% (96 runs sampled)
fastest is dot-prop |
Thanks for posting it. Clearly I like getting the best performance possible, or I wouldn't waste my time with adding benchmarks. But IMHO it's more important to actually pass the unit tests, and last time I checked dot-prop failed several of them |
I've find two segment of improvement after studying the benchmark results:
prop in obj
is slow (https://github.com/jonschlinkert/get-value/blob/master/index.js#L22-L24)Improves A LOT
a, b, c
could be deleted (https://github.com/jonschlinkert/get-value/blob/master/index.js#L15-L20)The text was updated successfully, but these errors were encountered: