public void Run(int entryCount)
            {
                var collectionCountBefore = GC.CollectionCount(0);

                _stopwatch.Restart();

                for (int i = 0; i < entryCount; i++)
                {
                    var securityId = _random.Next(_prices.Length);
                    _prices[securityId] += 5 - _random.Next(10);

                    _marketDataUpdate.Last = _prices[securityId];

                    using (var acquire = _targetEngine.AcquireEvent())
                    {
                        acquire.Event.SetMarketData(securityId, _marketDataUpdate);
                    }

                    UpdateCount++;
                    Thread.SpinWait(1 + _random.Next(1 << 5));
                }

                _stopwatch.Stop();
                Console.WriteLine($"Elapsed: {_stopwatch.Elapsed}");

                var collectionCount = GC.CollectionCount(0) - collectionCountBefore;

                Console.WriteLine($"CollectionCount: {collectionCount}");
            }
예제 #2
0
        private static void MeasureLatency(int blockCount)
        {
            var entrySize = blockCount * XEvent.BlockSize;

            var engine = new XEngine(entrySize);

            engine.Start();

            var  beginIndex = 0;
            byte sequence   = 0;

            for (var i = 0; i < 10 * 1000 * 1000; i++)
            {
                var endIndex = beginIndex + XEvent.BlockSize - 1;

                using (var acquireScope = engine.AcquireEvent())
                {
                    var evt = acquireScope.Event;
                    for (var dataIndex = beginIndex; dataIndex <= endIndex; dataIndex++)
                    {
                        evt.Data[dataIndex] = sequence++;
                    }
                    evt.BeginOffset = beginIndex;
                    evt.EndOffset   = endIndex;
                    evt.Timestamp   = Stopwatch.GetTimestamp();
                }

                beginIndex = (beginIndex + XEvent.BlockSize) % entrySize;
            }

            engine.Stop();
            engine.Dispose();
        }