domenic/chai-as-promised — pull request #15 by RubenVerborgh (2013-01-10 10:23:13+00:00)
Title: Speed up by searching for properties only once

Profiling revealed that Chai as Promised spends quite some time in descriptor-related methods:
```
[C++]:
ticks total nonlib name
1731 5.0% 5.0% v8::internal::Marker::MarkDescriptorArray
1229 3.6% 3.6% v8::internal::JSObject::LookupInDescriptor
1183 3.4% 3.4% v8::internal::DescriptorArray::BinarySearch
777 2.3% 2.3% v8::internal::DescriptorArray::CopyInsert
480 1.4% 1.4% v8::internal::DescriptorArray::CopyFrom
```

This code moves the search for properties to the start of the code, so it only executes once. The resulting code still spends a lot of time in MarkDescriptorArray, but it is way faster on the testcase of Issue #14.

On the following stress test of `eventually`, this patch takes only 9s instead of 23s.

```javascript
var chai = require("chai");
var Q = require("q");
chai.should();
chai.use(require("chai-as-promised"));

var repeats = 1000;
for(var i = 0; i < repeats; i++)
Q.delay('x', 10).should.eventually.be.a('string').notify(function () {
if (!--repeats)
console.log("done");
});
```