timer.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.lang.aspect.timer"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.lang.aspect.timer"] = true;
  8. dojo.provide("dojox.lang.aspect.timer");
  9. (function(){
  10. var aop = dojox.lang.aspect,
  11. uniqueNumber = 0;
  12. var Timer = function(name){
  13. this.name = name || ("DojoAopTimer #" + ++uniqueNumber);
  14. this.inCall = 0;
  15. };
  16. dojo.extend(Timer, {
  17. before: function(/*arguments*/){
  18. if(!(this.inCall++)){
  19. console.time(this.name);
  20. }
  21. },
  22. after: function(/*excp*/){
  23. if(!--this.inCall){
  24. console.timeEnd(this.name);
  25. }
  26. }
  27. });
  28. aop.timer = function(/*String?*/ name){
  29. // summary:
  30. // Returns an object, which can be used to time calls to methods.
  31. //
  32. // name:
  33. // The optional unique name of the timer.
  34. return new Timer(name); // Object
  35. };
  36. })();
  37. }