Loading ...
Sorry, an error occurred while loading the content.

34161RE: [ydn-javascript] Re: YUI Profiler statistics aren't consistent always.

Expand Messages
  • Nicholas Zakas
    Jul 9, 2008
    • 0 Attachment

      Hi Narendra,

       

      I’m afraid I don’t have any additional insights into why you’re seeing the results you’re seeing, especially if using Date objects yields a more consistent result. You are doing a lot of DOM manipulation, which can cause swings in execution time based on the number of iterations through the various loops that you have. But again, if the Date object approach is yielding more consistent results, I’m completely stumped because that’s essentially what the profiler does.

       

      The only way I’d really be able to get even close to an idea about what’s going on would be to have a functional example that I could play around with for a while. Short of that, I’m out of ideas.

       

      Regards,

      Nicholas

       

       


      From: ydn-javascript@yahoogroups.com [mailto: ydn-javascript@yahoogroups.com ] On Behalf Of mnrbug
      Sent: Thursday, July 03, 2008 10:58 PM
      To: ydn-javascript@yahoogroups.com
      Subject: [ydn-javascript] Re: YUI Profiler statistics aren't consistent always.

       


      Thanks Nicholas for the reply.

      Explanation as you requested :

      [1] "XYZ.u.d" is the namespace.
      We have registered all the functions of this namespace using:
      YAHOO.tool.Profiler .registerFunctio n( XYZ.u.d.funcNames );

      [2] And then, we got the full report using :
      var report = YAHOO.tool.Profiler .getFullReport( function( report){return
      report.calls> 0;});

      [3] Iterated through the results to display:
      for (var func in report){
      ...
      }

      [4] An example API which is showing varied statistics is :

      function XYZ.u.d.resizeAccor dion(){
      var accordArr = new Array();
      var totalIndex = XYZ.u.d.tabViewInde x;
      for(var i = 0; i < totalIndex; i++ ){
      var accordDivRef = document.getElement ById('PEGA_ ACCORDION' + i );
      if( accordDivRef != null ){
      accordArr.push( accordDivRef) ;
      }
      }
      var bActiveDiv = false;
      var accordArrLength = accordArr.length;
      for(var i=accordArrLength- 1;i>=0; i--) {
      var children =
      accordArr[i] .getElementsByTa gName("ul" )[0].childNodes;

      var childLen = children.length;
      for(var cnt=0; cnt < childLen; cnt++){
      if (children[cnt] .nodeType == 1 && children[cnt] .tagName == 'LI' ){
      contentDivs = children[cnt] .childNodes;
      for(var divcnt=0; divcnt < contentDivs. length; divcnt++){
      if (contentDivs[ divcnt].nodeType == 1 &&
      contentDivs[ divcnt].tagName == 'DIV' &&
      contentDivs[ divcnt].style. display == 'block' ){
      bActiveDiv = true;
      var activeTabDivContent = contentDivs[ divcnt];
      var firstChildDiv = activeTabDivContent .firstChild;
      var newHeight = 0;
      if(!YAHOO.util. Event.isIE) {
      while(firstChildDiv != null){
      if(firstChildDiv. nodeName == '#text'){
      firstChildDiv = firstChildDiv. nextSibling;
      }else{
      break;
      }
      }
      newHeight = this.getHeight( firstChildDiv) ;
      }
      var newTabHideContent = function() {
      activeTabDivContent .style.overflow= "visible" ;
      activeTabAnim. onComplete. unsubscribe( newTabHideConten t);

      }
      activeTabAnim = new YAHOO.util.Anim( activeTabDivCont ent);
      activeTabAnim. useSeconds = false;
      activeTabAnim. duration = XYZ.u.d.AccordionAn imSpeed;
      if(YAHOO.util. Event.isIE) newHeight = this.getHeight(
      firstChildDiv) ;

      activeTabAnim. onComplete. subscribe( newTabHideConten t,activeTabAnim, activeTabAnim) ;
      activeTabAnim. attributes. height = { to:newHeight };
      activeTabDivContent .style.overflow= "hidden";
      activeTabAnim. animate() ;
      break;
      }
      }
      }
      if(bActiveDiv) break;
      }
      }
      }

      [5] Interestingly, when we do :

      function XYZ.u.d.resizeAccor dion(){
      var starttime = (new Date()).getTime( );
      ......//old code from top.
      var endtime = (new Date()).getTime( );
      alert('Total time : ' + (endtime - starttime) );
      }

      We are getting accurate values for each run. But, Profiler is giving
      as I said before varied statistics.

      Please let me know in case you need any further information.

      Thanks,
      Narendra Reddy.Manchala

      --- In ydn-javascript@ yahoogroups. com, " Nicholas Zakas " <nzakas@...>
      wrote:

      >
      > Hi Narendra,
      >
      >
      >
      > Without seeing the code you're testing or how you're using the profiler,
      > it's a bit difficult to understand the issue you may be having.
      >
      >
      >
      > I can tell you that the profiler relies on the browser's Date objects to
      > do its timing, and since that implementation is accurate only down to
      > milliseconds, it is possible to see slightly different timings for the
      > same function over time. The best way to avoid this is to run the
      > function to be profiled as many times as possible (often more than 1000)
      > times, which will help to smooth out the timing differences.
      >
      >
      >
      > If you're still seeing large differences, it's probably something in
      > your function that is the culprit, as it makes no difference to the
      > profiler if a function is run once, twice, etc.
      >
      >
      >
      > -Nicholas
      >
      >
      >
      > ____________ _________ _________ __
      >
      > From: ydn-javascript@ yahoogroups. com
      > [mailto:ydn-javascript@ yahoogroups. com]
      On Behalf Of narendra reddy
      > Sent: Wednesday, July 02, 2008 5:38 AM
      > To: ydn-javascript@ yahoogroups. com
      > Subject: [ydn-javascript] YUI Profiler statistics aren't consistent
      > always.
      >
      >
      >
      > Hi there,
      >
      >
      >
      > We are using YUI Profiler to profile our Javascript APIs.
      >
      >
      >
      > Interestingly, the values are increasing when we run YUI Profiler for
      > the same API repeatedly.
      >
      > Ideally, the values should have decreased from second run onwards, as
      > caching comes into picture.
      >
      >
      >
      > For example :
      >
      > API : harnessResize( )
      >
      > 1st run 2nd run 3rd run
      >
      > 78msec 63msec 109msec
      >
      >
      >
      > Why is the 3rd run value greater?.
      >
      >
      >
      > Also, even the 1st run value isn't always consistent. That is, when we
      > re-open the browser, then we are getting different value(s).
      >
      >
      >
      > Please let us know the exact reason behind this weird behavior.
      >
      >
      >
      >
      >
      > Thanks,
      >
      > Narendra Reddy.Manchala.
      >

    • Show all 5 messages in this topic