Documentation
¶
Index ¶
- Constants
- func DiffTimeStamps(t_earlier, t_later TimeStamp) int64
- func FloatsEqualWithTolerance(f1, f2, tolerancePercentage float64) bool
- func GetSampleTimePrecision() int64
- func Median(data []float64) float64
- func QuickMedian(xs []float64) float64
- func Statistics(data []float64) (mean, variance, stddev float64)
- type DPRNG
- type RTcomparisonResult
- type TimeStamp
Constants ¶
const MinimumDataPoints uint64 = 11
Variables ¶
This section is empty.
Functions ¶
func DiffTimeStamps ¶
Retruns the difference between two timestams in nanoseconds with the highest possible precision (which might be more than just one nanosecond). The function assumes that t_later is later than t_earlier and will return a negative value if this is not the case. Please note that the call to this function does NOT have constant runtime on other systems but Windows.
func FloatsEqualWithTolerance ¶
FloatsEqualWithTolerance reports whether f1 and f2 are approximately equal, using a percentage-based absolute tolerance computed from each operand.
The tolerancePercentage parameter is interpreted as a percentage (for example, 5 means 5%). For each value v the function computes
absTol = |v * tolerancePercentage / 100|
and checks whether the other value lies within [v - absTol, v + absTol]. The function returns true if either check succeeds (i.e. if f2 is within the tolerance computed from f1 OR f1 is within the tolerance computed from f2).
Important notes:
- The comparison uses absolute tolerances derived from the operands, which makes the check effectively two-sided: a small value may be considered equal to a much larger one if the larger value's tolerance range contains the smaller value.
- A tolerancePercentage of 0 requires exact equality.
- Negative tolerancePercentage values are treated equivalently to their absolute value because the computed tolerance is wrapped with math.Abs.
- Comparisons involving NaN follow IEEE754 semantics and will not be true; interactions with ±Inf follow IEEE754 and may produce true results when a computed tolerance range is infinite.
- This function performs simple arithmetic checks and returns a boolean.
func GetSampleTimePrecision ¶
func GetSampleTimePrecision() int64
Returns the precision of time measurements obtained via SampleTime() on the runtime system in nanoseconds. Should return 100ns on Windows systems, and typically between 20ns and 100ns on Linux and MacOS systems.
func Median ¶
Median computes the median of the provided slice of float64. If data is empty, Median returns 0.0. The function makes a copy of the input and sorts the copy, so the original slice is not modified. For an odd-length slice it returns the middle element; for an even-length slice it returns the element at index len(data)/2 (the upper middle). Time complexity: O(n log n). Space complexity: O(n) due to the copy required for sorting.
func QuickMedian ¶
QuickMedian returns the median in expected O(n) time. In case of an odd number of elements, it returns the middle one. In case of an even number of elements, it returns the higher of the two middle ones. Returns math.NaN() for an empty input slice. Note: This function modifies the input array. To avoid this, pass a copy.
func Statistics ¶
Statistics computes the arithmetic mean, population variance, and standard deviation of the provided slice of float64 values.
It returns three float64s in order: mean, variance, and stddev.
The variance returned is the population variance (sum of squared deviations divided by n). The standard deviation is the square root of that variance.
If the input slice is empty, the function returns mean = 0 and variance = stddev = -1 to indicate that the values are undefined for an empty dataset.
Types ¶
type DPRNG ¶
DPRNG is a Deterministic Pseudo-Random Number Generator based on the xorshift* algorithm (see https://en.wikipedia.org/wiki/Xorshift#xorshift*). This randum number generator is deterministic in the sequence of numbers it generates. It has a period of 2^64-1, i.e. every single number occurs every 2^64-1 calls and has the same successor and the same predecessor. This randum number generator is deterministic its runtime (i.e. it has a constant runtime). This randum number generator is not cryptographically secure. This randum number generator is not thread-safe. This random number generator has a very small memory footprint (16 bytes). The initial state must not be zero.
func NewDPRNG ¶ added in v0.1.1
NewDPRNG creates a new DPRNG instance. If no seed is provided, it initializes the state with a random non-zero value. If the provided seed is zero, it initializes the state with a random non-zero value. Otherwise, it uses the provided seed value.
func (*DPRNG) Float64 ¶
Float64 returns a pseudo-random float64 in the range [0.0, 1.0) like Go’s math/rand.Float64(). It has a deterministic (i.e. constant) runtime and a high probability to be inlined by the compiler. The generated float64 values are uniformly distributed in the range [0.0, 1.0) with the effective precision of 53 bits (IEEE 754 compliant).
type RTcomparisonResult ¶
func CompareRuntimes ¶
func CompareRuntimes(sampleA, sampleB []float64, relativeSpeedupsToTest []float64, precisionLevel uint64) (result []RTcomparisonResult, err error)
CompareRuntimes compares two samples of runtimes (in float64, e.g., milliseconds) and computes the confidence that sample A is faster than sample B by at least the specified relative speedups. The precisionLevel parameter controls the number of bootstrap repetitions (higher values yield more precise results of the statistical tests but take longer to compute). It returns a slice of RTcomparisonResult, each containing one of the given relative speedup and the corresponding confidence level calculated by the statistical test. If there are not enough data points in either sample, an error is returned.
type TimeStamp ¶
A relative TimeStamp with the highest possible precision on the current runtime system. The values aren't comparable between computer restarts or between computers. They are only comparable on the same computer between two calls to SampleTime() within the same runtime of a program.
func SampleTime ¶
func SampleTime() TimeStamp
SampleTime returns a timestamp with the highest possible precision on the current runtime system.