public void LengthTimesLengthEqualsArea() { var m1 = new Metres(1); var m2 = new Metres(1); Area a = m1 * m2; Assert.AreEqual(1, a, 1e-6); }
public void VolumeDividedByLengthEqualsArea() { Volume volume = new CubicMetres(1); Length length = new Metres(1); Area area = volume / length; Assert.AreEqual(1, area, 1e-6); }
public void LengthDividedByLengthEqualsValue() { var m1 = new Metres(4); var m2 = new Metres(20); double v = m1 / m2; Assert.AreEqual(0.2, v, 1e-6); }
public void LengthTimesAreaEqualsVolume() { Area area = new SquareMetres(1); Length length = new Metres(1); Volume volume = length * area; Assert.AreEqual(1, volume, 1e-6); }
static MetresPerSecond DoMathsWithStructs() { Metres tenKms = 10 * 1000; Seconds oneHour = 60 * 60; return(tenKms / oneHour); }
public void AreaTimesLengthEqualsVolume() { Area area = new SquareMetres(1); Length length = new Metres(1); Volume volume = area * length; Assert.AreEqual(1, volume, 1e-6); }
public void MetresToFeet() { Metres m = new Metres(1); Feet ft = (new Feet(0)).From(m); // 1 metre = 3.2808399 feet (3 feet 3⅜ inches) Assert.AreEqual(3.2808399, ft.Value, 4); }
static void Main(string[] args) { // ----- Memory ----- WriteLine("Press enter to start memory stats"); ReadLine(); var baseline = GC.GetTotalMemory(forceFullCollection: true); var darray = new double[1000000]; var after = GC.GetTotalMemory(forceFullCollection: true); WriteLine("array of a million doubles is {0} bytes\n", after - baseline); baseline = GC.GetTotalMemory(forceFullCollection: true); var marray = new Metres[1000000]; after = GC.GetTotalMemory(forceFullCollection: true); WriteLine("array of a million Metres is {0} bytes\n", after - baseline); GC.KeepAlive(darray); GC.KeepAlive(marray); // ----- Cpu ----- Console.WriteLine("Press enter for maths"); Console.ReadLine(); for (int i = 0; i < 1000; i++) // "warmup" JIT { DoMaths(); DoMathsWithStructs(); } var sw = Stopwatch.StartNew(); for (int i = 0; i < 50000000; i++) { DoMaths(); } sw.Stop(); WriteLine($"raw maths took {sw.ElapsedMilliseconds}ms"); sw.Restart(); for (int i = 0; i < 50000000; i++) { DoMathsWithStructs(); } sw.Stop(); WriteLine($"struct maths took {sw.ElapsedMilliseconds}ms"); }
static void Main(string[] args) { // ----- Memory ----- WriteLine("Press enter to start memory stats"); ReadLine(); var baseline = GC.GetTotalMemory(forceFullCollection: true); var darray = new double[1000000]; var after = GC.GetTotalMemory(forceFullCollection: true); WriteLine("array of a million doubles is {0} bytes\n", after - baseline); baseline = GC.GetTotalMemory(forceFullCollection: true); var marray = new Metres[1000000]; after = GC.GetTotalMemory(forceFullCollection: true); WriteLine("array of a million Metres is {0} bytes\n", after - baseline); GC.KeepAlive(darray); GC.KeepAlive(marray); // ----- Cpu ----- Console.WriteLine("Press enter for maths"); Console.ReadLine(); for (int i = 0; i < 1000; i++) { // "warmup" JIT DoMaths(); DoMathsWithStructs(); } var sw = Stopwatch.StartNew(); for(int i = 0; i < 50000000; i++) DoMaths(); sw.Stop(); WriteLine($"raw maths took {sw.ElapsedMilliseconds}ms"); sw.Restart(); for (int i = 0; i < 50000000; i++) DoMathsWithStructs(); sw.Stop(); WriteLine($"struct maths took {sw.ElapsedMilliseconds}ms"); }
//----------------------------------------------------------------------------------------------- // Object //----------------------------------------------------------------------------------------------- public override int GetHashCode() { return(Metres.GetHashCode()); }
public override string ToString() { return($"{Metres.ToString("#,##0")}m ({Feet.ToString("#,##0")}ft)"); }
public int CompareTo(Height other) { return(Metres.CompareTo(other.Metres)); }
public int CompareTo(Length other) => Metres.CompareTo(other.Metres);