예제 #1
0
        public static void Test()
        {
            int  N         = 1000000;
            int  variation = 10000000;
            long listStart = -1;

            var timer = Stopwatch.StartNew();
            var ar    = new ulong[N];

            using (var mem = new MemoryStorage())
            {
                using (var writer = new DeltaVarIntListWriter(mem.GetReference()))
                {
                    var s1   = writer.StartList();
                    var prev = 0UL;
                    var r    = new Random(2019);
                    for (int i = 0; i < N; ++i)
                    {
                        prev += 1 + (ulong)r.Next(variation);
                        ar[i] = prev;
                        writer.AddValue(prev);
                    }
                    var e1 = writer.EndList();
                    Console.WriteLine($"Count  : {N}");
                    Console.WriteLine($"Length : {e1 - s1}");

                    listStart = s1;
                }
                Console.WriteLine($"Write  : {timer.Elapsed}");

                timer = Stopwatch.StartNew();
                using (var reader = new DeltaVarIntListReader(mem.GetReference()))
                {
                    int i = 0;
                    foreach (var v in reader.Get(listStart))
                    {
                        if (ar[i] != v)
                        {
                            throw new Exception($"{ar[i]} != {v} at {i}");
                        }
                        ++i;
                    }
                }
                Console.WriteLine($"Read   : {timer.Elapsed}");

                timer = Stopwatch.StartNew();
                using (var reader = new DeltaVarIntListReader(mem.GetReference()))
                {
                    for (int i = 0; i < N; ++i)
                    {
                        var v = reader.GetLowerBound(listStart, ar[i]).First();
                        if (ar[i] != v)
                        {
                            throw new Exception($"{ar[i]} != {v} at {i}");
                        }
                    }
                }
                Console.WriteLine($"Seek   : {timer.Elapsed}");
            }
        }