Skip to content

Optimizing selectors is wrong? #697

@franciscop

Description

@franciscop

Hello everyone, I made an alternative to jquery and was testing it against jquery for performance. I also wanted to test the most optimized jquery selectors and ended up in jquery's Optimize Selectors page. However, when testing it in Phantom JS (based on webkit), this doesn't seem to hold true:

$( ".buttons > *" ); // Extremely expensive.
$( ".buttons" ).children(); // Much better.

The first one seems to be faster for my situation. This is the test that should fail if jquery's page is true:

it("jquery vs jquery: mistake?", function() {

  var aTime = performance(function(){
    $(".ro > *");
  }, 100);

  var bTime = performance(function(){
    $(".ro").children();
  }, 100);

  console.log('a: ' + aTime + 'ms ', 'b: ' + bTime + 'ms');

  expect(aTime).to.be.below(bTime, uTime + ' ms');
});

However the test passes and in the terminal it's printed:

a: 203ms  b: 369ms

In the browser, the test also passes and it's "wrong":

a: 217ms  b: 264ms

So, was it an optimization for a previous version? is it a wrong optimization? Or it's just that it depends on the situation? (therefore, it's wrong stating it as an optimization)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions