tmpvar/jsdom — pull request #775 by tantaman (2014-05-22 21:36:48+00:00)
Title: lazily require "request"

Hey, this is related to https://github.com/chad3814/CSSStyleDeclaration/pull/14

I'll give you a quick summary.

We have a tool that loads jsdom as a dependency.
We run the tool pretty often as part of our dev process so its load time is pretty important to us. `request` is a pretty big module and this change reduces the time to `require('jsdom')` by about 30 - 50% (depends on what version of css style you have now ;) by not loading `request` until it is actually used.

I think lazily loading `request` makes sense since many use cases don't involve loading stuff via a url.

Here is a script you can use to time requiring jsdom:

```javascript
function timeFn(fn) {
var start = process.hrtime();

fn();

var elapsed = process.hrtime(start);
var ms = elapsed[1] / 1000000
console.log(elapsed[0] + 's ' + ms + ' ms');
}

timeFn(function() {
var jsdom = require('jsdom');
});
```

and here is a way to run it a bunch of times and average the results:
```bash
for i in {1..100}; do node jsdomLoad.js; done | awk -F" " '{print $2}' | awk '{T+= $NF} END { print T/NR }'
````

Thanks.