Logo Search packages:      
Sourcecode: jasmin-sable version File versions  Download package

static String java_cup::Main::timestr ( long  time_val,
long  total_time 
) [inline, static, protected]

Helper routine to format a decimal based display of seconds and percentage of total time given counts of milliseconds. Note: this is broken for use with some instances of negative time (since we don't use any negative time here, we let if be for now).

Parameters:
time_val the value being formatted (in ms).
total_time total time percentages are calculated against (in ms).

Definition at line 733 of file Main.java.

Referenced by show_times().

    {
      boolean neg;
      long    ms = 0;
      long    sec = 0;
      long    percent10;
      String  pad;

      /* work with positives only */
      neg = time_val < 0;
      if (neg) time_val = -time_val;

      /* pull out seconds and ms */
      ms = time_val % 1000;
      sec = time_val / 1000;

      /* construct a pad to blank fill seconds out to 4 places */
      if (sec < 10)   
      pad = "   ";
      else if (sec < 100)  
      pad = "  ";
      else if (sec < 1000) 
      pad = " ";
      else
      pad = "";

      /* calculate 10 times the percentage of total */
      percent10 = (time_val*1000)/total_time;

      /* build and return the output string */
      return (neg ? "-" : "") + pad + sec + "." + 
           ((ms%1000)/100) + ((ms%100)/10) + (ms%10) + "sec" +
           " (" + percent10/10 + "." + percent10%10 + "%)";
    }


Generated by  Doxygen 1.6.0   Back to index