public void BeginExecution() { var totalStopwatch = Stopwatch.StartNew(); var totalCount = 0; try { stopEvent.Reset(); while (true) { if (stopEvent.WaitOne(0)) { break; } totalCount += objectsPerBatch; DoWrite(); var actualSpeed = SpeedMeasurement.FromMeasurement(totalCount, totalStopwatch.Elapsed); if (actualSpeed.Speed > speed) { var timeoutToGetDesiredSpeed = actualSpeed.TimeoutToGetDesiredSpeed(speed); Thread.Sleep(timeoutToGetDesiredSpeed); } } } finally { totalStopwatch.Stop(); var totalSpeed = OperationsSpeed.PerTimeSpan(totalCount, totalStopwatch.Elapsed); ResultAverageSpeed = totalSpeed; } }
public TestEventWriter(IEventRepository repository, OperationsSpeed speed, int objectsPerBatch) { this.repository = repository; this.speed = speed; this.objectsPerBatch = objectsPerBatch; stopEvent = new ManualResetEvent(false); }
public TimeSpan TimeoutToGetDesiredSpeed(OperationsSpeed speed) { return(TimeSpan.FromMilliseconds(operations / (speed.OperationsPerSecond / 1000) - interval.TotalMilliseconds)); }