示例#1
0
        /// <summary>
        /// Tests writing to an array.
        /// </summary>
        public static void TestWrite(ArrayProfile profile)
        {
            using (var mapStream = new FileInfo(Global.FileName).Open(
                FileMode.Create, FileAccess.ReadWrite))
            {
                using (var map = new MemoryMapStream(mapStream))
                {
                    var array = new Array<int>(map, Global.ArrayTestLength,
                        profile);

                    var perf = new PerformanceInfoConsumer(
                        string.Format("Write Array: {0}", profile.ToString()), 
                            1000);
                    perf.Start();
                    for (var i = 0; i < array.Length; i++)
                    {
                        array[i] = i * 2;

                        if (Global.Verbose && i % (array.Length / 100) == 0)
                        {
                            perf.Report("Writing... {0}%", i, array.Length - 1);
                        }
                    }
                    perf.Stop();
                }
            }
        }
示例#2
0
        /// <summary>
        /// Tests read from an array.
        /// </summary>
        public static void TestRead(ArrayProfile profile)
        {
            using (var mapStream = new FileInfo(Global.FileName).Open(
                FileMode.Open, FileAccess.ReadWrite))
            {
                using (var map = new MemoryMapStream(mapStream))
                {
                    var array = new Array<int>(map.CreateInt32(mapStream.Length / 4), profile);

                    var perf = new PerformanceInfoConsumer(
                        string.Format("Read Array: {0}", profile.ToString()),
                            1000);
                    perf.Start();
                    for (var i = 0; i < array.Length; i++)
                    {
                        var val = array[i];
                        if (val != i * 2)
                        { // oeps, something went wrong here!
                            throw new System.Exception();
                        }

                        if (Global.Verbose && i % (array.Length / 100) == 0)
                        {
                            perf.Report("Reading... {0}%", i, array.Length - 1);
                        }
                    }
                    perf.Stop();

                    //var size = 1000000;
                    //perf = new PerformanceInfoConsumer(
                    //    string.Format("Read Random Array: {0} {1}", size, profile.ToString()),
                    //        1000);
                    //perf.Start();
                    //var rand = new Random();
                    //for (var i = 0; i < size; i++)
                    //{
                    //    var ran = (long)rand.Next((int)array.Length);
                    //    var val = array[ran];
                    //    if (val != ran * 2)
                    //    { // oeps, something went wrong here!
                    //        throw new System.Exception();
                    //    }

                    //    if (Global.Verbose && i % (size / 100) == 0)
                    //    {
                    //        perf.Report("Reading... {0}%", i, size);
                    //    }
                    //}
                    //perf.Stop();
                }
            }
        }