Skip to content

Commit

Permalink
Run 'dotnet format'.
Browse files Browse the repository at this point in the history
  • Loading branch information
atmoos committed May 19, 2024
1 parent 379505d commit 8e7cd65
Show file tree
Hide file tree
Showing 43 changed files with 497 additions and 501 deletions.
1 change: 1 addition & 0 deletions source/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ indent_size = 4
#### Core EditorConfig Options ####

#### .NET Coding Conventions ####
dotnet_style_readonly_field = true
dotnet_style_predefined_type_for_member_access = false:warning
dotnet_style_predefined_type_for_locals_parameters_members = false:warning
dotnet_style_qualification_for_field = true:suggestion
Expand Down
38 changes: 19 additions & 19 deletions source/Atmoos.Quantities.Benchmark/AddingQuantities.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
using BenchmarkDotNet.Diagnosers;
using Atmoos.Quantities.Prefixes;
using Atmoos.Quantities.Prefixes;
using Atmoos.Quantities.Units.Imperial.Length;
using Atmoos.Quantities.Units.Si;
using BenchmarkDotNet.Diagnosers;

namespace Atmoos.Quantities.Benchmark;

[MemoryDiagnoser(displayGenColumns: false)]
public class AddingQuantities
{
private Length sameMetric = Length.Of(-7, Si<Kilo, Metre>());
private Length largeMetric = Length.Of(3, Si<Kilo, Metre>());
private Length smallMetric = Length.Of(23, Si<Micro, Metre>());
private Length largeImperial = Length.Of(-3, Imperial<Mile>());
private Length smallImperial = Length.Of(55, Imperial<Inch>());
private Si<Metre> largeTrivial = Si<Metre>.Of(Prefix.Kilo, 3);
private Si<Metre> smallTrivial = Si<Metre>.Of(Prefix.Micro, 12);
private Length sameMetric = Length.Of(-7, Si<Kilo, Metre>());
private Length largeMetric = Length.Of(3, Si<Kilo, Metre>());
private Length smallMetric = Length.Of(23, Si<Micro, Metre>());
private Length largeImperial = Length.Of(-3, Imperial<Mile>());
private Length smallImperial = Length.Of(55, Imperial<Inch>());
private Si<Metre> largeTrivial = Si<Metre>.Of(Prefix.Kilo, 3);
private Si<Metre> smallTrivial = Si<Metre>.Of(Prefix.Micro, 12);

[Benchmark(Baseline = true)]
public Double Trivial() => this.largeTrivial + this.smallTrivial;
[Benchmark(Baseline = true)]
public Double Trivial() => this.largeTrivial + this.smallTrivial;

[Benchmark]
public Double AddSi() => this.largeMetric + this.smallMetric;
[Benchmark]
public Double AddSi() => this.largeMetric + this.smallMetric;

[Benchmark]
public Double AddSiSame() => this.sameMetric + this.largeMetric;
[Benchmark]
public Double AddSiSame() => this.sameMetric + this.largeMetric;

[Benchmark]
public Double AddImperial() => this.largeImperial + this.smallImperial;
[Benchmark]
public Double AddImperial() => this.largeImperial + this.smallImperial;

[Benchmark]
public Double AddMixed() => this.smallMetric + this.largeImperial;
[Benchmark]
public Double AddMixed() => this.smallMetric + this.largeImperial;
}

/* Summary
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Atmoos.Quantities.Benchmark;
namespace Atmoos.Quantities.Benchmark;

file interface IFactory<out T>
{
Expand Down
2 changes: 1 addition & 1 deletion source/Atmoos.Quantities.Benchmark/Convenience.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Text.Json;
using Newtonsoft.Json;
using Atmoos.Quantities.Core.Numerics;
using Atmoos.Quantities.Serialization.Text.Json;
using Atmoos.Quantities.Units.Si.Metric;
using Newtonsoft.Json;
using JsonSerializer = System.Text.Json.JsonSerializer;

namespace Atmoos.Quantities.Benchmark;
Expand Down
2 changes: 1 addition & 1 deletion source/Atmoos.Quantities.Benchmark/ConversionBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Runtime.CompilerServices;
using System.Runtime.CompilerServices;
using Atmoos.Quantities.Core.Numerics;

namespace Atmoos.Quantities.Benchmark;
Expand Down
28 changes: 14 additions & 14 deletions source/Atmoos.Quantities.Benchmark/ConvertingQuantities.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Atmoos.Quantities.Prefixes;
using Atmoos.Quantities.Prefixes;
using Atmoos.Quantities.Units.Imperial.Length;
using Atmoos.Quantities.Units.Si;
using Atmoos.Quantities.Units.Si.Derived;
Expand All @@ -8,23 +8,23 @@ namespace Atmoos.Quantities.Benchmark;
[MemoryDiagnoser(displayGenColumns: false)]
public class ConvertingQuantities
{
private const Double feetToMetre = 0.3048;
private static readonly Si<Metre> kiloMetre = Si<Metre>.Of(Prefix.Kilo, 3);
private static readonly Imperial<Foot> trivialFoot = new(10, feetToMetre);
private static readonly Length foot = Length.Of(10, Imperial<Foot>());
private static readonly Energy energy = Energy.Of(3, Si<Milli, Watt>().Times(Si<Kilo, Second>()));
private const Double feetToMetre = 0.3048;
private static readonly Si<Metre> kiloMetre = Si<Metre>.Of(Prefix.Kilo, 3);
private static readonly Imperial<Foot> trivialFoot = new(10, feetToMetre);
private static readonly Length foot = Length.Of(10, Imperial<Foot>());
private static readonly Energy energy = Energy.Of(3, Si<Milli, Watt>().Times(Si<Kilo, Second>()));

[Benchmark(Baseline = true)]
public Double TrivialImplementation() => trivialFoot.To(kiloMetre);
[Benchmark(Baseline = true)]
public Double TrivialImplementation() => trivialFoot.To(kiloMetre);

[Benchmark]
public Double QuantityImplementation() => foot.To(Si<Kilo, Metre>());
[Benchmark]
public Double QuantityImplementation() => foot.To(Si<Kilo, Metre>());

[Benchmark]
public Double QuantityToSame() => energy.To(Si<Milli, Watt>().Times(Si<Kilo, Second>()));
[Benchmark]
public Double QuantityToSame() => energy.To(Si<Milli, Watt>().Times(Si<Kilo, Second>()));

[Benchmark]
public Double QuantityToVeryDifferent() => energy.To(Si<Kilo, Watt>().Times(Si<Milli, Second>()));
[Benchmark]
public Double QuantityToVeryDifferent() => energy.To(Si<Kilo, Watt>().Times(Si<Milli, Second>()));
}

/* Summary
Expand Down
4 changes: 2 additions & 2 deletions source/Atmoos.Quantities.Benchmark/CreateQuantities.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Diagnosers;
using System.Runtime.CompilerServices;
using Atmoos.Quantities.Prefixes;
using Atmoos.Quantities.Units.Si;
using Atmoos.Quantities.Units.Si.Derived;
using Atmoos.Quantities.Units.Si.Metric;
using BenchmarkDotNet.Diagnosers;

namespace Atmoos.Quantities.Benchmark;

Expand Down
50 changes: 25 additions & 25 deletions source/Atmoos.Quantities.Benchmark/DeserializationBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Atmoos.Quantities.Prefixes;
using Atmoos.Quantities.Prefixes;
using Atmoos.Quantities.Units.Si;
using Atmoos.Quantities.Units.Si.Derived;
using Atmoos.Quantities.Units.Si.Metric;
Expand All @@ -8,30 +8,30 @@ namespace Atmoos.Quantities.Benchmark;
[MemoryDiagnoser(displayGenColumns: false)]
public class DeserializationBenchmark
{
private static readonly String triple = Triple().Serialize();
private static readonly String simpleQuantity = Length.Of(Math.PI, Si<Metre>()).Serialize();
private static readonly String prefixedQuantity = Length.Of(Math.PI, Si<Kilo, Metre>()).Serialize();
private static readonly String fractionalQuantity = Velocity.Of(Math.PI, Si<Kilo, Metre>().Per(Metric<Hour>())).Serialize();
private static readonly String multiplicativeQuantity = Energy.Of(Math.PI, Si<Kilo, Watt>().Times(Metric<Hour>())).Serialize();
private static readonly String powerQuantity = Volume.Of(Math.PI, Cubic(Si<Deci, Metre>())).Serialize();
private static readonly String scalarPowerQuantity = Volume.Of(Math.PI, Metric<Deci, Litre>()).Serialize();

[Benchmark(Baseline = true)]
public (Double, String, String) SystemTriple() => triple.Deserialize<(Double, String, String)>();
[Benchmark]
public Length SystemQuantity() => simpleQuantity.Deserialize<Length>();
[Benchmark]
public Length PrefixedQuantity() => prefixedQuantity.Deserialize<Length>();
[Benchmark]
public Velocity FractionalQuantity() => fractionalQuantity.Deserialize<Velocity>();
[Benchmark]
public Energy MultiplicativeQuantity() => multiplicativeQuantity.Deserialize<Energy>();
[Benchmark]
public Volume PowerQuantity() => powerQuantity.Deserialize<Volume>();
[Benchmark]
public Volume ScalarPowerQuantity() => scalarPowerQuantity.Deserialize<Volume>();

private static (Double value, String prefix, String unit) Triple() => (Math.PI, "K", "m");
private static readonly String triple = Triple().Serialize();
private static readonly String simpleQuantity = Length.Of(Math.PI, Si<Metre>()).Serialize();
private static readonly String prefixedQuantity = Length.Of(Math.PI, Si<Kilo, Metre>()).Serialize();
private static readonly String fractionalQuantity = Velocity.Of(Math.PI, Si<Kilo, Metre>().Per(Metric<Hour>())).Serialize();
private static readonly String multiplicativeQuantity = Energy.Of(Math.PI, Si<Kilo, Watt>().Times(Metric<Hour>())).Serialize();
private static readonly String powerQuantity = Volume.Of(Math.PI, Cubic(Si<Deci, Metre>())).Serialize();
private static readonly String scalarPowerQuantity = Volume.Of(Math.PI, Metric<Deci, Litre>()).Serialize();

[Benchmark(Baseline = true)]
public (Double, String, String) SystemTriple() => triple.Deserialize<(Double, String, String)>();
[Benchmark]
public Length SystemQuantity() => simpleQuantity.Deserialize<Length>();
[Benchmark]
public Length PrefixedQuantity() => prefixedQuantity.Deserialize<Length>();
[Benchmark]
public Velocity FractionalQuantity() => fractionalQuantity.Deserialize<Velocity>();
[Benchmark]
public Energy MultiplicativeQuantity() => multiplicativeQuantity.Deserialize<Energy>();
[Benchmark]
public Volume PowerQuantity() => powerQuantity.Deserialize<Volume>();
[Benchmark]
public Volume ScalarPowerQuantity() => scalarPowerQuantity.Deserialize<Volume>();

private static (Double value, String prefix, String unit) Triple() => (Math.PI, "K", "m");
}

/* Summary
Expand Down
60 changes: 30 additions & 30 deletions source/Atmoos.Quantities.Benchmark/DividingQuantities.cs
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
using BenchmarkDotNet.Diagnosers;
using Atmoos.Quantities.Prefixes;
using Atmoos.Quantities.Prefixes;
using Atmoos.Quantities.Units.Imperial.Area;
using Atmoos.Quantities.Units.Imperial.Length;
using Atmoos.Quantities.Units.Si;
using Atmoos.Quantities.Units.Si.Derived;
using Atmoos.Quantities.Units.Si.Metric;
using BenchmarkDotNet.Diagnosers;

namespace Atmoos.Quantities.Benchmark;

[MemoryDiagnoser(displayGenColumns: false)]
public class DividingQuantities
{
private Volume metricVolume = Volume.Of(3, Cubic(Si<Kilo, Metre>()));
private Volume metricAcceptedVolume = Volume.Of(3, Metric<Kilo, Litre>());
private Area metricArea = Area.Of(23, Square(Si<Deca, Metre>()));
private Area imperialPureArea = Area.Of(23, Imperial<Acre>());
private Volume imperialVolume = Volume.Of(-3, Cubic(Imperial<Mile>()));
private Area imperialArea = Area.Of(55, Square(Imperial<Yard>()));
private ElectricPotential potential = ElectricPotential.Of(33, Si<Kilo, Volt>());
private ElectricCurrent current = ElectricCurrent.Of(98, Si<Deca, Ampere>());
private Si<Metre> largeTrivial = Si<Metre>.Of(Prefix.Kilo, 3);
private Si<Metre> smallTrivial = Si<Metre>.Of(Prefix.Micro, 12);

[Benchmark(Baseline = true)]
public Double Trivial() => this.largeTrivial / this.smallTrivial;

[Benchmark]
public Double DivideSi() => this.metricVolume / this.metricArea;

[Benchmark]
public Double DivideImperial() => this.imperialVolume / this.imperialArea;

[Benchmark]
public Double DivideMixed() => this.metricVolume / this.imperialArea;

[Benchmark]
public Double DivideAliased() => this.metricAcceptedVolume / this.imperialPureArea;

[Benchmark]
public Double DividePureSi() => this.potential / this.current;
private Volume metricVolume = Volume.Of(3, Cubic(Si<Kilo, Metre>()));
private Volume metricAcceptedVolume = Volume.Of(3, Metric<Kilo, Litre>());
private Area metricArea = Area.Of(23, Square(Si<Deca, Metre>()));
private Area imperialPureArea = Area.Of(23, Imperial<Acre>());
private Volume imperialVolume = Volume.Of(-3, Cubic(Imperial<Mile>()));
private Area imperialArea = Area.Of(55, Square(Imperial<Yard>()));
private ElectricPotential potential = ElectricPotential.Of(33, Si<Kilo, Volt>());
private ElectricCurrent current = ElectricCurrent.Of(98, Si<Deca, Ampere>());
private Si<Metre> largeTrivial = Si<Metre>.Of(Prefix.Kilo, 3);
private Si<Metre> smallTrivial = Si<Metre>.Of(Prefix.Micro, 12);

[Benchmark(Baseline = true)]
public Double Trivial() => this.largeTrivial / this.smallTrivial;

[Benchmark]
public Double DivideSi() => this.metricVolume / this.metricArea;

[Benchmark]
public Double DivideImperial() => this.imperialVolume / this.imperialArea;

[Benchmark]
public Double DivideMixed() => this.metricVolume / this.imperialArea;

[Benchmark]
public Double DivideAliased() => this.metricAcceptedVolume / this.imperialPureArea;

[Benchmark]
public Double DividePureSi() => this.potential / this.current;
}

/* Summary
Expand Down
4 changes: 2 additions & 2 deletions source/Atmoos.Quantities.Benchmark/MeasureBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Atmoos.Quantities.Measures;
using Atmoos.Quantities.Measures;
using Atmoos.Quantities.Prefixes;
using Atmoos.Quantities.Units.Imperial.Length;
using Atmoos.Quantities.Units.Si.Metric;
using Atmoos.Quantities.Units.Si;
using Atmoos.Quantities.Units.Si.Metric;

namespace Atmoos.Quantities.Benchmark;
public class MeasureBenchmark
Expand Down
52 changes: 26 additions & 26 deletions source/Atmoos.Quantities.Benchmark/MultiplyingQuantities.cs
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
using BenchmarkDotNet.Diagnosers;
using Atmoos.Quantities.Prefixes;
using Atmoos.Quantities.Prefixes;
using Atmoos.Quantities.Units.Imperial.Length;
using Atmoos.Quantities.Units.Si;
using Atmoos.Quantities.Units.Si.Derived;
using Atmoos.Quantities.Units.Si.Metric;
using BenchmarkDotNet.Diagnosers;

namespace Atmoos.Quantities.Benchmark;

[MemoryDiagnoser(displayGenColumns: false)]
public class MultiplyingQuantities
{
private Area aliasArea = Area.Of(3, Metric<Are>());
private Area powerArea = Area.Of(3, Square(Si<Metre>()));
private Length largeMetric = Length.Of(3, Si<Kilo, Metre>());
private Length smallMetric = Length.Of(23, Si<Micro, Metre>());
private Length largeImperial = Length.Of(-3, Imperial<Mile>());
private Length smallImperial = Length.Of(55, Imperial<Inch>());
private ElectricCurrent current = ElectricCurrent.Of(200, Si<Micro, Ampere>());
private ElectricalResistance resistance = ElectricalResistance.Of(734, Si<Kilo, Ohm>());
private Si<Metre> largeTrivial = Si<Metre>.Of(Prefix.Kilo, 3);
private Si<Metre> smallTrivial = Si<Metre>.Of(Prefix.Micro, 12);
private Area aliasArea = Area.Of(3, Metric<Are>());
private Area powerArea = Area.Of(3, Square(Si<Metre>()));
private Length largeMetric = Length.Of(3, Si<Kilo, Metre>());
private Length smallMetric = Length.Of(23, Si<Micro, Metre>());
private Length largeImperial = Length.Of(-3, Imperial<Mile>());
private Length smallImperial = Length.Of(55, Imperial<Inch>());
private ElectricCurrent current = ElectricCurrent.Of(200, Si<Micro, Ampere>());
private ElectricalResistance resistance = ElectricalResistance.Of(734, Si<Kilo, Ohm>());
private Si<Metre> largeTrivial = Si<Metre>.Of(Prefix.Kilo, 3);
private Si<Metre> smallTrivial = Si<Metre>.Of(Prefix.Micro, 12);

[Benchmark(Baseline = true)]
public Double Trivial() => this.largeTrivial * this.smallTrivial;
[Benchmark(Baseline = true)]
public Double Trivial() => this.largeTrivial * this.smallTrivial;

[Benchmark]
public Double MultiplySi() => this.largeMetric * this.smallMetric;
[Benchmark]
public Double MultiplySi() => this.largeMetric * this.smallMetric;

[Benchmark]
public Double MultiplyImperial() => this.largeImperial * this.smallImperial;
[Benchmark]
public Double MultiplyImperial() => this.largeImperial * this.smallImperial;

[Benchmark]
public Double MultiplyMixed() => this.smallMetric * this.largeImperial;
[Benchmark]
public Double MultiplyMixed() => this.smallMetric * this.largeImperial;

[Benchmark]
public Double MultiplyPureSi() => this.current * this.resistance;
[Benchmark]
public Double MultiplyPureSi() => this.current * this.resistance;

[Benchmark]
public Double MultiplyPowerQuantity() => this.powerArea * this.largeMetric;
[Benchmark]
public Double MultiplyPowerQuantity() => this.powerArea * this.largeMetric;

[Benchmark]
public Double MultiplyAliasQuantity() => this.aliasArea * this.largeMetric;
[Benchmark]
public Double MultiplyAliasQuantity() => this.aliasArea * this.largeMetric;
}

/* Summary
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using Atmoos.Quantities.Core.Numerics;
using Atmoos.Quantities.Core.Numerics;

namespace Atmoos.Quantities.Benchmark.Numerics;

public class AlgorithmsPowerBenchmark
{
private const Double value = Math.Tau;
private const Double value = Math.Tau;

[Params(2, 5, 12, 23)]
public Int32 Exponent { get; set; }
[Params(2, 5, 12, 23)]
public Int32 Exponent { get; set; }

[Benchmark(Baseline = true)]
public Double MathPow() => Math.Pow(value, Exponent);
[Benchmark(Baseline = true)]
public Double MathPow() => Math.Pow(value, Exponent);

[Benchmark]
public Double AlgorithmsPow() => Algorithms.Pow(value, Exponent);
[Benchmark]
public Double AlgorithmsPow() => Algorithms.Pow(value, Exponent);
}

/* Summary
Expand Down
Loading

0 comments on commit 8e7cd65

Please sign in to comment.