codemix/fast.js — pull request #19 by phpnode (2014-06-25 22:08:20+00:00)
Title: add proposed support for partial constructors

Opening this as a PR for discussion, this implements @jdalton's proposal for partial constructors in #17.

Here's the benchmark result:

```
Running 2 benchmarks, please wait...

Native .bind() vs fast.partial() vs underscore.partial() vs lodash.partial()
✓ Function::bind() x 846,794 ops/sec ±1.70% (80 runs sampled)
✓ fast.partial() x 6,301,578 ops/sec ±1.79% (90 runs sampled)
✓ fast.partial() v0.0.0 x 6,855,920 ops/sec ±2.17% (85 runs sampled)
✓ underscore.partial() x 1,437,070 ops/sec ±2.10% (86 runs sampled)
✓ lodash.partial() x 309,771 ops/sec ±2.28% (84 runs sampled)

Winner is: fast.partial() v0.0.0 (2113.22% faster)

Native .bind() vs fast.partial() with prebound functions
✓ Function::bind() x 4,392,286 ops/sec ±2.27% (85 runs sampled)
✓ fast.partial() x 14,326,034 ops/sec ±1.91% (84 runs sampled)
✓ fast.partial() v0.0.0 x 14,926,356 ops/sec ±1.98% (83 runs sampled)
✓ underscore.partial() x 6,669,546 ops/sec ±1.56% (90 runs sampled)
✓ lodash.partial() x 4,510,568 ops/sec ±1.44% (93 runs sampled)

Winner is: fast.partial() v0.0.0 (239.83% faster)
```

So the instance of check and the extra branch makes this slightly slower. Partial constructors are definitely an edge case, and while I'd like to support them I don't want to hurt (in a very small way) the performance of the 99% of code that doesn't use them. Maybe adding `fast.partialConstructor()` is the answer here, so that it can be called explicitly if required?