mtklein | 9ac68ee | 2014-06-20 11:29:20 -0700 | [diff] [blame] | 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" |
Jim Van Verth | 446cc84 | 2017-09-20 15:23:44 -0400 | [diff] [blame] | 8 | #include <stdio.h> |
mtklein | 9ac68ee | 2014-06-20 11:29:20 -0700 | [diff] [blame] | 9 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 10 | SkString HumanizeMs(double ms) { |
mtklein | d1f7f99 | 2015-03-12 10:29:32 -0700 | [diff] [blame] | 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); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 14 | #ifdef SK_BUILD_FOR_WIN |
mtklein | d1f7f99 | 2015-03-12 10:29:32 -0700 | [diff] [blame] | 15 | if (ms < 1) return SkStringPrintf("%.3gus", ms*1e+3); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 16 | #else |
mtklein | d1f7f99 | 2015-03-12 10:29:32 -0700 | [diff] [blame] | 17 | if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e+3); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 18 | #endif |
| 19 | return SkStringPrintf("%.3gms", ms); |
| 20 | } |
Jim Van Verth | 32bbf37 | 2017-09-20 12:53:00 -0400 | [diff] [blame] | 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, "%.3gµs", ms*1e+3); |
| 30 | #endif |
| 31 | return snprintf(s, len, "%.3gms", ms); |
| 32 | } |