saturnflyer/casting — pull request #22 by cbandy (2014-01-08 06:03:06+00:00)
Title: Look up the attendant only once

I see about a 20% improvement in the worst case.

```ruby
require 'benchmark'
require 'casting'

module A; def does; end; end
module B; def other; end; end
module C; end

class Thing
include Casting::Client
delegate_missing_methods
end

def measure(bm, name, it)
it.does
bm.report(name) { 10_000.times { it.does } }
end

Benchmark.bm(3) do |bm|
measure(bm, '1:', Thing.new.cast_as(A))
measure(bm, '2:', Thing.new.cast_as(A).cast_as(B))
measure(bm, '3:', Thing.new.cast_as(A).cast_as(B).cast_as(C))
end
```

```
fc810d9:
user system total real
1: 0.230000 0.000000 0.230000 ( 0.232505)
2: 0.300000 0.000000 0.300000 ( 0.293111)
3: 0.360000 0.000000 0.360000 ( 0.363260)

835d320:
user system total real
1: 0.190000 0.000000 0.190000 ( 0.188623)
2: 0.210000 0.000000 0.210000 ( 0.212040)
3: 0.250000 0.000000 0.250000 ( 0.248505)
```