public long Run(ThroughputSessionContext sessionContext)
    {
        long expectedCount = _eventProcessor.Sequence.Value + _iterations;

        _eventHandler.Reset(expectedCount);
        var processorTask = _eventProcessor.Start();

        _eventProcessor.WaitUntilStarted(TimeSpan.FromSeconds(5));

        sessionContext.Start();

        var ringBuffer = _ringBuffer;

        for (long i = 0; i < _iterations; i++)
        {
            var sequence = ringBuffer.Next();
            ringBuffer[sequence].Value = i;
            ringBuffer.Publish(sequence);
        }

        _eventHandler.WaitForSequence();
        sessionContext.Stop();
        PerfTestUtil.WaitForEventProcessorSequence(expectedCount, _eventProcessor);
        _eventProcessor.Halt();
        processorTask.Wait(2000);

        sessionContext.SetBatchData(_eventHandler.BatchesProcessed, _iterations);

        PerfTestUtil.FailIfNot(_expectedResult, _eventHandler.Value, $"Handler should have processed {_expectedResult} events, but was: {_eventHandler.Value}");

        return(_iterations);
    }
    public long Run(ThroughputSessionContext sessionContext)
    {
        var expectedCount = _eventProcessor.Sequence.Value + _iterations * _batchSize;

        _handler.Reset(expectedCount);
        var processorTask = _eventProcessor.Start();

        _eventProcessor.WaitUntilStarted(TimeSpan.FromSeconds(5));

        sessionContext.Start();

        var ringBuffer = _ringBuffer;

        for (var i = 0; i < _iterations; i++)
        {
            var hi = ringBuffer.Next(_batchSize);
            var lo = hi - (_batchSize - 1);
            for (var l = lo; l <= hi; l++)
            {
                ringBuffer[l].Value = (i);
            }
            ringBuffer.Publish(lo, hi);
        }

        _handler.WaitForSequence();
        sessionContext.Stop();
        PerfTestUtil.WaitForEventProcessorSequence(expectedCount, _eventProcessor);
        _eventProcessor.Halt();
        processorTask.Wait(2000);

        sessionContext.SetBatchData(_handler.BatchesProcessed, _iterations * _batchSize);

        PerfTestUtil.FailIfNot(_expectedResult, _handler.Value, $"Handler should have processed {_expectedResult} events, but was: {_handler.Value}");

        return(_batchSize * _iterations);
    }