Monday, May 19th, 2008
For these, a dynamic language isn’t as helpful. Eugene delves into the world and takes us to the module from first principles. He then builds a timer aspect which can be used to profile an application. Along with a memoizer and other useful cross cutting concerns, you end up with good ole Fibonaci:
- var fib = new Fibonacci;
- // we will time the calculations
- aop.advise(fib, "calculate", aop.timer("fib");
- // now lets use memoization
- aop.advise(fib, "calculate", aop.memoizer());
- aop.advise(fib, /^set/, aop.memoizerGuard("calculate"));
- fib.setOrder(1); // set order back to 1 - regular Fibonacci numbers
Memoization got results too:
On my computer with Firefox 3 the calculation of 1-order (regular) Fibonacci number of 15 (987) took ~48ms without memoization and 0-1ms after memoization. The calculation of 0-order Fibonacci number of 15 (32768) took ~1155ms without memoization and the same 0-1ms after. As you can see this technique can work wonders without much investment of time.
Just like with Java, we won’t see every developer worrying about pointcuts day to day, but instead, simple usage of existing advice will become very useful indeed.
Posted by Dion Almaer at 7:53 am