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