Beispiel #1
0
        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;
            }
        }
Beispiel #2
0
 public TestEventWriter(IEventRepository repository, OperationsSpeed speed, int objectsPerBatch)
 {
     this.repository      = repository;
     this.speed           = speed;
     this.objectsPerBatch = objectsPerBatch;
     stopEvent            = new ManualResetEvent(false);
 }
Beispiel #3
0
 public TimeSpan TimeoutToGetDesiredSpeed(OperationsSpeed speed)
 {
     return(TimeSpan.FromMilliseconds(operations / (speed.OperationsPerSecond / 1000) - interval.TotalMilliseconds));
 }