57
1
using System; using System.Text;
2
using System.Diagnostics;
3
4
public static class Program
5
{
6
/// <summary>
7
/// Human readable elapsed time Ticks using modern Action delegate, leaving out zero parts and variable length formatting
8
/// https://metadataconsulting.blogspot.com/2019/07/C-Sharp-Human-Readable-Ticks-with-microsecond-and-nanosecond-units.html
9
/// </summary>
10
/// <param name="ticks">a long type</param>
11
/// <returns>Human readable units place for microseconds & nanoseconds</returns>
12
public static string HumanReadableTicks(this long ticks)
13
{
14
if (ticks == 0) return "0 ns";
15
16
StringBuilder SB = new StringBuilder();
17
18
Action<long, string, int> addUnittoSB =
19
(val, displayunit, zeroplaces) =>
20
{
21
if (val > 0) //do not print this unit place if no value for it
22
{
23
SB.AppendFormat(
24
" {0:DZ}X".Replace("X", displayunit)
Cached Result