RobustHistogram

Namespace: SnowBank.Numerics · class

Helper that will aggregate individual measurements, and output detailed distribution reports and charts.

Constructors

RobustHistogram

RobustHistogram()

Constructs a new RobustHistogram for measuring durations with microsecond precision.

RobustHistogram(TimeScale scale)

Constructs a new RobustHistogram with the given TimeScale

Properties

Average

double Average { get; }

Compute the arithmetic average

Count

int Count { get; }

Number of samples that where measured so far: Ts.Count()

Dimension

DimensionType Dimension { get; }

Dimension of values measured by this histogram

HighThreshold

double HighThreshold { get; }

Maximum value of the highest bucket with at least one measurement

LowThreshold

double LowThreshold { get; }

Minimum value of the lowest bucket with at least one measurement

Max

double Max { get; }

Highest sample measured so far: Ts.Max()

Median

double Median { get; }

Compute the median of all measured samples (50% percentile)

Min

double Min { get; }

Lowest sample measured so far: Ts.Min()

Scale

TimeScale Scale { get; }

Timescale used by this histogram

StandardDeviation

double StandardDeviation { get; }

Compute the standard deviation

Sum

double Sum { get; }

Sum of all samples measured so far: Ts.Sum(t => t)

SumSquares

double SumSquares { get; }

Sum of the squares of all samples measured so far: Ts.Sum(t => t * t)

Methods

Add

void Add(double value)

Add a new measurement

The unit if the value should match the unit that was specified when the histogram was created

void Add(TimeSpan value)

Add a new duration measurement

AddNanos

void AddNanos(double nanos)

Add a new duration measurement, expressed in nanoseconds

AddTicks

void AddTicks(long ticks)

Add a new duration measurement, expressed in ticks (100 ns per tick)

Clear

void Clear()

Clear all samples from this histogram, so that it can be reused for another measurement run

FromNanoseconds

double FromNanoseconds(double value)

Convert a number of nanoseconds (ns) into the equivalent measured value

  • value — Number of seconds to convert

Returns: value converted from nanoseconds in the corresponding mesaured value

This only works if the histogram is measuring elapsed time.

GetDistribution

string GetDistribution(double begin = 1, double end = 1E+200, int fold = 0)

Generate an areaplot that will display the distribution of samples, by value

Returns: String that will look like this: " __xX=-___x___ "

GetDistributionAuto

string GetDistributionAuto()

Computes the distribution of data between the computed LowThreshold and HighThreshold

GetDistributionData

double[] GetDistributionData(double start = 1, double end = 1E+200)

Computes the distribution of data between the specified bounds

GetMaxThreshold

static double GetMaxThreshold(double value)

Computes the maximum threshold for the given value

GetMinThreshold

static double GetMinThreshold(double value)

Computes the minimum threshold for the given value

GetPercentile

string GetPercentile(double begin = 1, double end = 1E+200)

Generates a horizontal boxplot that displays the distribution of the sampled values

Returns: String that will look like "¤ ×·(——[==#===]——————)···× @".Legend: - '#' = MEDIAN - '¤', '@' = MIN, MAX - '[', ']' = P25, P75 - '(', ')' = P05, P95 - 'x' = P01, P99

GetPercentileAuto

string GetPercentileAuto()

Formats the percentile distribution between the computed LowThreshold and HighThreshold

GetPercentiles

string GetPercentiles()

Generate a short text description of the percentiles of this distribution

Returns: "P5 --| P25 == [ P50 ]== P75 |-- P95"

GetReport

string GetReport(bool detailed)

Generate a text report of the measurements, that can be written to the console or in a log file

  • detailed — If false, generate a simple table. If true, output a more detailed version with bar graphs, that could exceed 80 characters per line.

GetScale

static string GetScale(double start = 1, double end = 1E+200, string scaleString = null)

Truncate a distribution scale according to the specified range

GetScaleAuto

string GetScaleAuto(string scaleString = null)

Formats the scale between the computed LowThreshold and HighThreshold

MAD

double MAD()

Computes the Mean Absolute Deviation

Merge

void Merge(RobustHistogram other)

Merge the measurements of another histogram into this instance

  • other — Histogram that contains measurements from another run

Percentile

double Percentile(double p)

Computes the value of the given percentile p (0..100%)

  • p — Value of the percentile, expressed in % from 0 to 100 (ex: 50 is equivalent to the median)

Returns: Corresponding percentile value

ToBytes

double ToBytes(double value)

Convert a measured value into bytes

  • value — Value to convert (any of Median, Max, ...)

Returns: value converted into bytes

This only works if the histogram is measuring bytes.

double ToBytes(double value, int precision)

Convert a measured value into bytes with a given precision

  • value — Value to convert (any of Median, Max, ...)
  • precision — Number of digits for rounding

Returns: value converted into bytes and rounded to the specified precision

This only works if the histogram is measuring bytes.

ToGibiBytes

double ToGibiBytes(double value)

Convert a measured value into mebibytes (2^30 or 1,073,741,824 bytes)

  • value — Value to convert (any of Median, Max, ...)

Returns: value converted into gibibytes

If you want megabytes (10^9 bytes), please call instead.

double ToGibiBytes(double value, int precision)

Convert a measured value into mebibytes (2^30 or 1,073,741,824 bytes) with a given precision

  • value — Value to convert (any of Median, Max, ...)
  • precision — Number of digits for rounding

Returns: value converted into gibibytes and rounded to the specified precision

If you want megabytes (10^9 bytes), please call instead.

ToGigaBytes

double ToGigaBytes(double value)

Convert a measured value into megabytes (10^9 or 1,000,000,000 bytes)

  • value — Value to convert (any of Median, Max, ...)

Returns: value converted into gigabytes

If you want mebibytes (2^30 bytes), please call instead.

double ToGigaBytes(double value, int precision)

Convert a measured value into megabytes (10^9 or 1,000,000,000 bytes) with a given precision

  • value — Value to convert (any of Median, Max, ...)
  • precision — Number of digits for rounding

Returns: value converted into gigabytes and rounded to the specified precision

If you want mebibytes (2^30 bytes), please call instead.

ToKibiBytes

double ToKibiBytes(double value)

Convert a measured value into kibibytes (2^10 or 1024 bytes)

  • value — Value to convert (any of Median, Max, ...)

Returns: value converted into kibibytes

If you want kilobytes (1,000 bytes), please call instead.

double ToKibiBytes(double value, int precision)

Convert a measured value into kibibytes (2^10 or 1024 bytes) with a given precision

  • value — Value to convert (any of Median, Max, ...)
  • precision — Number of digits for rounding

Returns: value converted into kibibytes and rounded to the specified precision

If you want kilobytes (1,000 bytes), please call instead.

ToKiloBytes

double ToKiloBytes(double value)

Convert a measured value into kilobytes (10^3 or 1,000 bytes)

  • value — Value to convert (any of Median, Max, ...)

Returns: value converted into kilobytes

If you want kibibytes (1,024 bytes), please call instead.

double ToKiloBytes(double value, int precision)

Convert a measured value into kilobytes (10^3 or 1,000 bytes) with a given precision

  • value — Value to convert (any of Median, Max, ...)
  • precision — Number of digits for rounding

Returns: value converted into kilobytes and rounded to the specified precision

If you want kibibytes (1,024 bytes), please call instead.

ToMebiBytes

double ToMebiBytes(double value)

Convert a measured value into mebibytes (2^20 or 1,048,576 bytes)

  • value — Value to convert (any of Median, Max, ...)

Returns: value converted into mebibytes

If you want megabytes (10^6 bytes), please call instead.

double ToMebiBytes(double value, int precision)

Convert a measured value into mebibytes (2^20 or 1,048,576 bytes) with a given precision

  • value — Value to convert (any of Median, Max, ...)
  • precision — Number of digits for rounding

Returns: value converted into mebibytes and rounded to the specified precision

If you want megabytes (10^6 bytes), please call instead.

ToMegaBytes

double ToMegaBytes(double value)

Convert a measured value into megabytes (10^6 or 1,000,000 bytes)

  • value — Value to convert (any of Median, Max, ...)

Returns: value converted into megabytes

If you want mebibytes (2^20 bytes), please call instead.

double ToMegaBytes(double value, int precision)

Convert a measured value into megabytes (10^6 or 1,000,000 bytes) with a given precision

  • value — Value to convert (any of Median, Max, ...)
  • precision — Number of digits for rounding

Returns: value converted into megabytes and rounded to the specified precision

If you want mebibytes (2^20 bytes), please call instead.

ToMicroseconds

double ToMicroseconds(double value)

Convert a measured value into microseconds (µs)

  • value — Value to convert (any of Median, Max, ...)

Returns: value converted into microseconds

This only works if the histogram is measuring elapsed time.

double ToMicroseconds(double value, int precision)

Convert a measured value into microseconds (µs) with a given precision

  • value — Value to convert (any of Median, Max, ...)
  • precision — Number of digits for rounding

Returns: value converted into microseconds and rounded to the specified precision

This only works if the histogram is measuring elapsed time.

ToMilliseconds

double ToMilliseconds(double value)

Convert a measured value into milliseconds (ms)

  • value — Value to convert (any of Median, Max, ...)

Returns: value converted into milliseconds

This only works if the histogram is measuring elapsed time.

double ToMilliseconds(double value, int precision)

Convert a measured value into milliseconds (ms) with a given precision

  • value — Value to convert (any of Median, Max, ...)
  • precision — Number of digits for rounding

Returns: value converted into milliseconds and rounded to the specified precision

This only works if the histogram is measuring elapsed time.

ToNanoseconds

double ToNanoseconds(double value)

Convert a measured value into nanoseconds (ns)

  • value — Value to convert (any of Median, Max, ...)

Returns: value converted into nanoseconds

This only works if the histogram is measuring elapsed time.

double ToNanoseconds(double value, int precision)

Convert a measured value into nanoseconds (ns) with a given precision

  • value — Value to convert (any of Median, Max, ...)
  • precision — Number of digits for rounding

Returns: value converted into nanoseconds and rounded to the specified precision

This only works if the histogram is measuring elapsed time.

ToSeconds

double ToSeconds(double value)

Convert a measured value into seconds (s)

  • value — Value to convert (any of Median, Max, ...)

Returns: value converted into seconds

This only works if the histogram is measuring elapsed time.

double ToSeconds(double value, int precision)

Convert a measured value into seconds with a given precision

  • value — Value to convert (any of Median, Max, ...)
  • precision — Number of digits for rounding

Returns: value converted into seconds and rounded to the specified precision

This only works if the histogram is measuring elapsed time.

ToString

string ToString()

Warmup

static void Warmup()

Pre-JIT this type, before running a benchmark

Fields

HorizontalScale

const string HorizontalScale

First row of the horizontal scale (includes the number literals)

HorizontalShade

const string HorizontalShade

Second row of the horizontal scale (includes the ticks and markers)

MaxValue

const double MaxValue

Maximum value that can be measured (10E200)

MinValue

const double MinValue

Minimum value that can be measured (0)