timer.js 787 B

123456789101112131415161718192021222324252627282930313233343536
  1. // wrapped by build app
  2. define("dojox/lang/aspect/timer", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){
  3. dojo.provide("dojox.lang.aspect.timer");
  4. (function(){
  5. var aop = dojox.lang.aspect,
  6. uniqueNumber = 0;
  7. var Timer = function(name){
  8. this.name = name || ("DojoAopTimer #" + ++uniqueNumber);
  9. this.inCall = 0;
  10. };
  11. dojo.extend(Timer, {
  12. before: function(/*arguments*/){
  13. if(!(this.inCall++)){
  14. console.time(this.name);
  15. }
  16. },
  17. after: function(/*excp*/){
  18. if(!--this.inCall){
  19. console.timeEnd(this.name);
  20. }
  21. }
  22. });
  23. aop.timer = function(/*String?*/ name){
  24. // summary:
  25. // Returns an object, which can be used to time calls to methods.
  26. //
  27. // name:
  28. // The optional unique name of the timer.
  29. return new Timer(name); // Object
  30. };
  31. })();
  32. });