Performance characteristics of Measurements.jl
mainMeasurements.jl is designed for high performance. Benchmarks indicate that basic operations like creating a Measurement object, performing arithmetic (e.g., addition), and applying unary functions (e.g., sqrt, sin, gamma) have very low overhead, typically in the nanosecond range.
Key performance observations:
- Scalar Operations: Creating a measurement (e.g.,
4.7 ± 0.3) and performing arithmetic on two measurements are highly efficient. - Unary Functions: Functions with a single argument where functional correlation is not a concern are particularly fast.
- Vectorized Operations: Applying functions to vectors (using dot notation like
sqrt.(vector)) scales linearly with the size of the vector.
using Measurements, SpecialFunctions, BenchmarkTools
# Creation of a `Measurement` object
@benchmark 4.7 ± 0.3
# Sum of two `Measurement` objects
a = 12.3 ± 4.5; b = 67.8 ± 9.0;
@benchmark $a + $b
# Unary functions
@benchmark sqrt($b)
@benchmark sin($a)
@benchmark gamma($a)
# Vectorized operations
vector = [1 ± 0.1 for _ in 1:10000];
@benchmark sqrt.($vector)
@benchmark sin.($vector)
@benchmark gamma.($vector)
@benchmark cos.($vector) .^ 2 .+ sin.($vector) .^ 2