Skip to content

Commit

Permalink
Create Project Configuration for ProfilingUse TryGetValue in Metrics
Browse files Browse the repository at this point in the history
Language features and fix naming rule
  • Loading branch information
DRVeyl committed Jun 28, 2021
1 parent a737ed8 commit 2918e42
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions FerramAerospaceResearch.Base/Utils/Metrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ namespace FerramAerospaceResearch.Utils
{
public class Metrics
{
public Dictionary<string, MetricsElement> data = new Dictionary<string, MetricsElement>();
const int hysteresisFactor = 20;
public Dictionary<string, MetricsElement> data = new();
const int HysteresisFactor = 20;
public Metrics() { }
public void Reset() => data.Clear();
public void AddMeasurement(string name, double t)
{
if (!data.ContainsKey(name))
if (!data.TryGetValue(name, out MetricsElement m))
{
data.Add(name, new MetricsElement());
m = new MetricsElement();
data.Add(name, m);
}
MetricsElement m = data[name];
m.iterations++;
m.hysteresisTime = (m.hysteresisTime * (hysteresisFactor - 1) + t) / hysteresisFactor;
m.hysteresisTime = (m.hysteresisTime * (HysteresisFactor - 1) + t) / HysteresisFactor;
}
}

Expand Down

0 comments on commit 2918e42

Please sign in to comment.