-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cs
More file actions
56 lines (48 loc) · 1.36 KB
/
Copy pathUtils.cs
File metadata and controls
56 lines (48 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
namespace IoMonitor
{
/// <summary>
/// Generic formatting helpers used by the console UI.
/// </summary>
internal static partial class Program
{
/// <summary>
/// Formats a byte quantity into a human-friendly string (KB, MB, GB, ...).
/// </summary>
private static string FormatBytes(long bytes)
{
if (bytes == 0)
{
return "0 B";
}
string[] sizes = { "B", "KB", "MB", "GB", "TB" };
int order = 0;
double value = bytes;
while (value >= 1024 && order < sizes.Length - 1)
{
order++;
value /= 1024;
}
return $"{value:N2} {sizes[order]}";
}
/// <summary>
/// Formats a count of operations into a compact string (e.g. "1.2K", "3.4M").
/// </summary>
private static string FormatOps(long ops)
{
if (ops == 0)
{
return "0";
}
if (ops < 1000)
{
return ops.ToString();
}
if (ops < 1_000_000)
{
return $"{ops / 1000.0:F1}K";
}
return $"{ops / 1_000_000.0:F1}M";
}
}
}