Skip to content
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

Closed
leesei opened this issue Jan 19, 2016 · 7 comments
Closed

Benchmark result #5

leesei opened this issue Jan 19, 2016 · 7 comments

Comments

@leesei
Copy link

leesei commented Jan 19, 2016

I've find two segment of improvement after studying the benchmark results:

@jonschlinkert
Copy link
Owner

prop in obj is slow

yes, true. But not that slow, and unfortunately it's necessary to be able to get non-enumerable prototype methods.

extra params a, b, c could be deleted

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 .join keys, thus it actually results in a speed increase "round trip".

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 get method where the key is always prefixed with a specific property path:

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 get(this.views, key), but it's not as easy when you're inheriting or using an instance of something with a get method. We do this a lot in libs like base, since it will always be faster than checking arguments and joining the keys, then splitting them again in get-value

Plus, in the benchmarks that code does not have much of an impact on speed, since it's explicit.

hope that makes sense.

@leesei
Copy link
Author

leesei commented Jan 22, 2016

I see. That's the reason why this lib is slower than dot-prop (around 40-50% in the benchmark test).
I suggest highlighting this feature in README.


I understand the feature but never considered that use case.
Then we should also add this feature to README. I would stress that only 3 params are supported (which would fit most use case).

@jonschlinkert
Copy link
Owner

(around 40-50% in the benchmark test).

Interesting, I get 2.8m ops/sec for this lib versus 3m ops/sec for dot prop. what version of node are you running?

I would stress that only 3 params are supported (which would fit most use case).

good idea. closing this, but I'll open a new one for docs

@leesei
Copy link
Author

leesei commented Jan 22, 2016

I'm using Node 5.1.
I can post more results later.

On Fri, Jan 22, 2016 at 12:50 PM, Jon Schlinkert notifications@github.com
wrote:

Closed #5 #5.


Reply to this email directly or view it on GitHub
#5 (comment).

@leesei
Copy link
Author

leesei commented Jan 22, 2016

$ 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

@leesei
Copy link
Author

leesei commented Jan 22, 2016

$ 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

@jonschlinkert
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants