/// <summary> /// Mark the passage of time and decay the current rate accordingly. /// </summary> public void Tick(long timestamp) { var count = _uncounted.GetAndSet(0); long interval = timestamp - _lastTick; var instantRate = count / (double)interval; if (_initialized) { _rate += _alpha * (instantRate - _rate); } else { var expectedIntervalInNanoseconds = _expectedTickInterval.TotalMilliseconds * 1000000; if (interval < expectedIntervalInNanoseconds * 0.7) { // The tick occured too soon to have meaningful data return; } _rate.Set(instantRate); _initialized = true; } _lastTick = timestamp; }
public void VolatileDouble_CanGetAndSetValue() { var value = new VolatileDouble(1.5); value.GetValue().Should().Be(1.5); value.SetValue(2.3); value.GetValue().Should().Be(2.3); }
public void can_get_and_set_value() { var value = new VolatileDouble(1.5); value.GetValue().Should().Be(1.5); value.SetValue(2.3); value.GetValue().Should().Be(2.3); }
public void Can_get_and_set_value_non_volatile() { var value = new VolatileDouble(1.5); value.NonVolatileGetValue().Should().Be(1.5); value.NonVolatileSetValue(2.3); value.NonVolatileGetValue().Should().Be(2.3); }
public void Can_add_through_wrapper() { var rate1 = 15.50; rate1 += (2 * 10 - rate1); Trace.WriteLine(rate1); VolatileDouble rate2 = 15.50; rate2 += (2 * 10 - rate2); Trace.WriteLine(rate2); Assert.AreEqual(rate1, (double)rate2); }
/// <summary> /// Mark the passage of time and decay the current rate accordingly. /// </summary> public void Tick() { var count = _uncounted.GetAndSet(0); var instantRate = count / _interval; if (_initialized) { _rate += _alpha * (instantRate - _rate); } else { _rate.Set(instantRate); _initialized = true; } }