blob: 6f04c981502f911dd936450aa947820071b26e22 [file] [log] [blame]
mtklein9ac68ee2014-06-20 11:29:20 -07001/*
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 Verth446cc842017-09-20 15:23:44 -04008#include <stdio.h>
mtklein9ac68ee2014-06-20 11:29:20 -07009
mtklein748ca3b2015-01-15 10:56:12 -080010SkString HumanizeMs(double ms) {
mtkleind1f7f992015-03-12 10:29:32 -070011 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);
mtklein748ca3b2015-01-15 10:56:12 -080014#ifdef SK_BUILD_FOR_WIN
mtkleind1f7f992015-03-12 10:29:32 -070015 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e+3);
mtklein748ca3b2015-01-15 10:56:12 -080016#else
mtkleind1f7f992015-03-12 10:29:32 -070017 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e+3);
mtklein748ca3b2015-01-15 10:56:12 -080018#endif
19 return SkStringPrintf("%.3gms", ms);
20}
Jim Van Verth32bbf372017-09-20 12:53:00 -040021
22int 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}