static IEnumerable<long> TestQuantityTypes(int N) { Console.WriteLine("=== QuantityTypes ==="); var length = Marshal.SizeOf(typeof(Length)); Console.WriteLine("Length = {0} bytes", length); yield return length; var a1 = new Length[N]; var a2 = new Area[N]; using (var timer = new Timer("Assign")) { for (int i = 0; i < N; i++) a1[i] = Length.Metre; } using (var timer = new Timer("Assign (multiplication)")) { for (int i = 0; i < N; i++) a1[i] = i * Length.Metre; yield return timer.Stop(); } using (var timer = new Timer("Assign (ctor)")) { for (int i = 0; i < N; i++) a1[i] = new Length(i); yield return timer.Stop(); } using (var timer = new Timer("Add (operator)")) { for (int i = 0; i < N; i++) a1[i] = a1[i] + a1[0]; yield return timer.Stop(); } #if PublicFields using (var timer=new Timer("Add (field)")) { for (int i = 0; i < N; i++) a1[i] = new Length(a1[i].value + a1[0].value); } #endif using (var timer = new Timer("Add (property)")) { for (int i = 0; i < N; i++) a1[i] = new Length(a1[i].Value + a1[0].Value); yield return timer.Stop(); } var s = "10"; using (var timer = new Timer("Parse")) { for (int i = 0; i < N; i++) a1[i] = Length.Parse(s); yield return timer.Stop(); } s = "10 m"; using (var timer = new Timer("Parse with unit")) { for (int i = 0; i < N; i++) a1[i] = Length.Parse(s); yield return timer.Stop(); } using (var timer = new Timer("Multiply")) { for (int i = 0; i < N; i++) a2[i] = a1[i] * a1[i]; yield return timer.Stop(); } #if PublicFields using (var timer=new Timer("Multiply (field)")) { for (int i = 0; i < N; i++) a2[i] = new Area(a1[i].value * a1[i].value); yield return timer.Stop(); } #endif using (var timer = new Timer("Multiply (property, ctor)")) { for (int i = 0; i < N; i++) a2[i] = new Area(a1[i].Value * a1[i].Value); yield return timer.Stop(); } using (var timer = new Timer("Multiply (property, multiplication)")) { for (int i = 0; i < N; i++) a2[i] = (a1[i].Value * a1[i].Value) * Area.SquareMetre; } using (var timer = new Timer("Square")) { for (int i = 0; i < N; i++) a2[i] = a1[i].Squared(); } using (var timer = new Timer("^")) { for (int i = 0; i < N; i++) a2[i] = (Area)(a1[i] ^ 2); } double sum1; using (var timer = new Timer("Sum (operator)")) { var sum = new Area(); for (int i = 0; i < N; i++) sum += a2[i]; sum1 = sum.ConvertTo(Area.SquareMetre); yield return timer.Stop(); } #if PublicFields double sum2 = 0; using (var timer=new Timer("Sum (field)")) { for (int i = 0; i < N; i++) sum2 += a2[i].value; } #endif double sum3 = 0; using (var timer = new Timer("Sum (property)")) { for (int i = 0; i < N; i++) sum3 += a2[i].Value; yield return timer.Stop(); } Console.WriteLine(); }
public void XmlValue_RoundTrip_ValuesShouldBeEqual() { var l1 = 4.0 / 7 * Length.Metre; var l2 = new Length { XmlValue = l1.XmlValue }; Assert.AreEqual(l1, l2); }
/// <summary> /// Returns the angle whose tangent is the quotient of the two specified numbers. /// </summary> /// <param name="y">The y coordinate of a point.</param> /// <param name="x">The x coordinate of a point.</param> /// <returns>An angle, θ, measured in radians, such that -π ≤ θ ≤ π, and tan(θ) = y / x, where (x, y) is a point in the Cartesian plane.</returns> public static Angle Atan2(Length y, Length x) { return new Angle(Math.Atan2(y.Value, x.Value)); }