Home | History | Annotate | Download | only in timer
      1 /*
      2  * Copyright 2011 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 #include "Timer.h"
      8 #include <stdio.h>
      9 
     10 SkString HumanizeMs(double ms) {
     11     if (ms > 60e+3)  return SkStringPrintf("%.3gm", ms/60e+3);
     12     if (ms >  1e+3)  return SkStringPrintf("%.3gs",  ms/1e+3);
     13     if (ms <  1e-3)  return SkStringPrintf("%.3gns", ms*1e+6);
     14 #ifdef SK_BUILD_FOR_WIN
     15     if (ms < 1)      return SkStringPrintf("%.3gus", ms*1e+3);
     16 #else
     17     if (ms < 1)      return SkStringPrintf("%.3gs", ms*1e+3);
     18 #endif
     19     return SkStringPrintf("%.3gms", ms);
     20 }
     21 
     22 int HumanizeMs(char* s, int len, double ms) {
     23     if (ms > 60e+3)  return snprintf(s, len, "%.3gm", ms / 60e+3);
     24     if (ms >  1e+3)  return snprintf(s, len, "%.3gs", ms / 1e+3);
     25     if (ms <  1e-3)  return snprintf(s, len, "%.3gns", ms*1e+6);
     26 #ifdef SK_BUILD_FOR_WIN
     27     if (ms < 1)      return snprintf(s, len, "%.3gus", ms*1e+3);
     28 #else
     29     if (ms < 1)      return snprintf(s, len, "%.3gs", ms*1e+3);
     30 #endif
     31     return snprintf(s, len, "%.3gms", ms);
     32 }
     33