Example #1
0
        public void MemoryAccessVecViaDbVecStorageUnsafe(RetainableMemory <int> rm)
        {
            var  rounds = TestUtils.GetBenchCount(100_000, 100);
            long sum    = 0;

            using (Benchmark.Run("DbVecStorageUnsafe (+)", rm.Length * rounds))
            {
                DataBlockLike db = new DataBlockLike {
                    Rm = rm, Vec = rm.GetVec().AsVec(), RetainedVec = RetainedVec.Create(rm, 0, rm.Length, true)
                };

                for (int r = 0; r < rounds; r++)
                {
                    for (long i = 0; i < rm.Length; i++)
                    {
                        sum += db.RetainedVec.Vec.UnsafeGetUnaligned <int>((IntPtr)i);
                    }
                }
            }

            if (sum < 1000)
            {
                throw new InvalidOperationException();
            }
        }
Example #2
0
        public void MemoryAccessVecViaLocalUnsafe(RetainableMemory <int> rm)
        {
            var  rounds = TestUtils.GetBenchCount(10_000, 100);
            long sum    = 0;

            using (Benchmark.Run("LocalUnsafe", rm.Length * rounds))
            {
                var vec = rm.GetVec().AsVec();
                for (int r = 0; r < rounds; r++)
                {
                    for (long i = 0; i < rm.Length; i++)
                    {
                        sum += vec.UnsafeGetUnaligned <int>((IntPtr)i);
                    }
                }
            }

            if (sum < 1000)
            {
                throw new InvalidOperationException();
            }
        }
Example #3
0
        public unsafe void MemoryAccessVecViaDbVecPointer(RetainableMemory <int> rm)
        {
            var  rounds = TestUtils.GetBenchCount(100_000, 100);
            long sum    = 0;

            using (Benchmark.Run("DbVecPointer (*)", rm.Length * rounds))
            {
                DataBlockLike db = new DataBlockLike {
                    Rm = rm, Vec = rm.GetVec().AsVec(), Ptr = (int *)rm.Pointer
                };
                for (int r = 0; r < rounds; r++)
                {
                    for (long i = 0; i < rm.Length; i++)
                    {
                        sum += Unsafe.ReadUnaligned <int>(ref Unsafe.As <int, byte>(ref Unsafe.Add <int>(ref Unsafe.AsRef <int>((void *)db.Vec._byteOffset), (IntPtr)i)));
                    }
                }
            }

            if (sum < 1000)
            {
                throw new InvalidOperationException();
            }
        }
Example #4
0
        public void MemoryAccessVecViaDbVecDangerous(RetainableMemory <int> rm)
        {
            long sum    = 0;
            var  rounds = TestUtils.GetBenchCount(10_000, 100);

            using (Benchmark.Run("DbVecDangerous (+)", rm.Length * rounds))
            {
                DataBlockLike db = new DataBlockLike {
                    Rm = rm, Vec = rm.GetVec().AsVec()
                };
                for (int r = 0; r < rounds; r++)
                {
                    for (int i = 0; i < rm.Length; i++)
                    {
                        sum += db.Vec.DangerousGetUnaligned <int>(i);
                    }
                }
            }

            if (sum < 1000)
            {
                throw new InvalidOperationException();
            }
        }