Ejemplo n.º 1
0
        public unsafe MemoryAccessBenchmark()
        {
            // Create a memory mapped file and fill it with random bytes
            _memory = new MemoryMappedFileMemory(ItemLength * ItemCount);
            GenerateRandomBytes(_memory.DataPointer, _memory.Length);
            _readOnlyBuffer = _memory.CreateReadOnlyBuffer();

            // Create the same RNG for both benchmarks
            _random = XorShiftRandom.Create(0x6780867534);

            // Allocate 5 bytes for the
            _constantMemoryPointer = Marshal.AllocHGlobal(5);
        }
Ejemplo n.º 2
0
        private static unsafe void GenerateRandomBytes(byte *pointer, long count)
        {
            // Forget about alignment since this test will run on x64
            ulong *p = (ulong *)pointer;
            long   c = count >> 3;

            var random = XorShiftRandom.Create(0x2985194649313);

            for (int i = 0; i < c; i++)
            {
                *p++ = random.Next();
            }

            int remainingBytes = (int)(count & 0x7);

            if (remainingBytes > 0)
            {
                ulong n = random.Next();

                new Span <byte>(&n, remainingBytes).CopyTo(new Span <byte>(p, remainingBytes));
            }
        }