コード例 #1
0
        public void Read()
        {
            var filepath = "PerformanceTest2";


            var context = new StorageContext <MyDataItem>(filepath, "Name");
            var item2   = new MyDataItem();

            item2.Name = "awef0";
            context.Add(item2);
            context.Dispose();

            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Start();
            context = new StorageContext <MyDataItem>(filepath, "Name");
            for (int i = 0; i < 1000000; i++)
            {
                var item = new MyDataItem();
                item.Name = "Jack" + i;
                context.Add(item);
            }

            watch.Stop();
            Debug.WriteLine($"总耗时:{watch.ElapsedMilliseconds}ms");

            watch.Reset();
            watch.Start();
            var list = context.Where(m => m.Name.Contains("ack1")).ToArray();

            watch.Stop();
            Debug.WriteLine($"读取总耗时:{watch.ElapsedMilliseconds}ms");

            System.IO.File.Delete(filepath);
        }
        public void Read()
        {
            var filepath = "server.PerformanceTest2";


            var context = new StorageContext <MyDataItem>("localhost", 8227, filepath, "Name");

            context.GetType().GetMethod("DeleteFile", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(context, null);

            var item2 = new MyDataItem();

            item2.Name = "awef0";
            context.Add(item2);
            context.Dispose();

            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Start();
            context = new StorageContext <MyDataItem>("localhost", 8227, filepath, "Name");
            for (int i = 0; i < 100000; i++)
            {
                var item = new MyDataItem();
                item.Name = "Jack" + i;
                context.Add(item);
            }

            watch.Stop();
            Debug.WriteLine($"总耗时:{watch.ElapsedMilliseconds}ms");

            watch.Reset();
            watch.Start();
            var list = context.Where(m => m.Name.Contains("ack1")).ToArray();

            watch.Stop();
            Debug.WriteLine($"读取总耗时:{watch.ElapsedMilliseconds}ms");
        }
コード例 #3
0
        public void SyncAdd()
        {
            var filepath = "PerformanceTest";


            var context = new StorageContext <MyDataItem>(filepath, "Name", false);
            var item2   = new MyDataItem();

            item2.Name = "awef0";
            context.Add(item2);
            context.Dispose();

            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Start();
            context = new StorageContext <MyDataItem>(filepath, "Name");
            for (int i = 0; i < 1000000; i++)
            {
                var item = new MyDataItem();
                item.Name = "Jack" + i;
                context.Add(item);
            }

            watch.Stop();
            Debug.WriteLine($"同步写入总耗时:{watch.ElapsedMilliseconds}ms");

            context.Dispose();

            System.IO.File.Delete(filepath);
        }
コード例 #4
0
        public void Add()
        {
            var name = "ServerTest.Add";


            var context = new StorageContext <MyDataItem>("localhost", 8227, name, "Name");

            context.GetType().GetMethod("DeleteFile", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(context, null);

            System.Threading.Tasks.Parallel.For(0, 100, (i) => {
                var item  = new MyDataItem();
                item.Name = "Jack" + i;
                context.Add(item);
            });

            context.Dispose();

            context = new StorageContext <MyDataItem>("localhost", 8227, name, "Name");
            if (context.Count != 100)
            {
                throw new Exception("数量不对,当前数量:" + context.Count);
            }

            for (int i = 0; i < 100; i++)
            {
                if (context.Any(m => m.Name == "Jack" + i) == false)
                {
                    throw new Exception("没有这个对象");
                }
            }

            context.Dispose();
        }
        public void AddAsync()
        {
            var filepath = "server.PerformanceTest.async";
            var total    = 1000000;

            var context = new StorageContext <MyDataItem>("localhost", 8227, filepath, "Name", true);

            context.GetType().GetMethod("DeleteFile", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(context, null);

            var item2 = new MyDataItem();

            item2.Name = "awef0";
            context.Add(item2);
            context.Dispose();

            context = new StorageContext <MyDataItem>("localhost", 8227, filepath, "Name", true);
            System.Diagnostics.Stopwatch watch  = new System.Diagnostics.Stopwatch();
            System.Diagnostics.Stopwatch watch2 = new System.Diagnostics.Stopwatch();
            watch2.Start();
            watch.Start();
            for (int i = 0; i < total; i++)
            {
                var item = new MyDataItem();
                item.Name = "Jack" + i;
                context.Add(item);
            }

            watch.Stop();
            Debug.WriteLine($"{total/10000}万数据写入总耗时:{watch.ElapsedMilliseconds}ms");

            context.Dispose();
            watch2.Stop();
            Debug.WriteLine($"写入文件总耗时:{watch2.ElapsedMilliseconds}ms");
        }
コード例 #6
0
        public void Remove()
        {
            var name = "ServerTest.Remove";


            var context = new StorageContext <MyDataItem>("localhost", 8227, name, "Name");

            context.GetType().GetMethod("DeleteFile", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(context, null);

            System.Threading.Tasks.Parallel.For(0, 100, (i) => {
                var item  = new MyDataItem();
                item.Name = "Jack" + i;
                context.Add(item);
            });

            if (context.Count != 100)
            {
                throw new Exception("数量不对");
            }

            context.Dispose();

            context = new StorageContext <MyDataItem>("localhost", 8227, name, "Name");
            if (context.Count != 100)
            {
                throw new Exception("数量不对");
            }

            var datas = context.ToArray();

            System.Threading.Tasks.Parallel.For(0, datas.Length, (i) => {
                context.Remove(datas[i]);
            });


            context.Dispose();

            context = new StorageContext <MyDataItem>("localhost", 8227, name, "Name");
            if (context.Count != 0)
            {
                throw new Exception("数量不对");
            }


            context.Dispose();
        }
コード例 #7
0
        public void Remove()
        {
            var filepath = "Remove";


            var context = new StorageContext <MyDataItem>(filepath, "Name");

            System.Threading.Tasks.Parallel.For(0, 10000, (i) => {
                var item  = new MyDataItem();
                item.Name = "Jack" + i;
                context.Add(item);
            });

            if (context.Count != 10000)
            {
                throw new Exception("数量不对");
            }

            context.Dispose();

            context = new StorageContext <MyDataItem>(filepath, "Name");
            if (context.Count != 10000)
            {
                throw new Exception("数量不对");
            }

            var datas = context.ToArray();

            System.Threading.Tasks.Parallel.For(0, datas.Length, (i) => {
                context.Remove(datas[i]);
            });


            context.Dispose();

            context = new StorageContext <MyDataItem>(filepath, "Name");
            if (context.Count != 0)
            {
                throw new Exception("数量不对");
            }


            System.IO.File.Delete(filepath);
        }
コード例 #8
0
        public void Update()
        {
            var name = "ServerTest.Update";


            var context = new StorageContext <MyDataItem>("localhost", 8227, name, "Name");

            context.GetType().GetMethod("DeleteFile", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(context, null);

            System.Threading.Tasks.Parallel.For(0, 10, (i) => {
                var item  = new MyDataItem();
                item.Name = "Jack" + i;
                context.Add(item);
            });

            if (context.Count != 10)
            {
                throw new Exception("数量不对");
            }

            var obj = context.FirstOrDefault(m => m.Name == "Jack5");

            obj.Company = "abc";
            context.Update(obj);

            context.Dispose();



            context = new StorageContext <MyDataItem>("localhost", 8227, name, "Name");
            if (context.Count != 10)
            {
                throw new Exception("数量不对");
            }

            obj = context.FirstOrDefault(m => m.Name == "Jack5");
            if (obj.Company != "abc")
            {
                throw new Exception("数据错误");
            }

            context.Dispose();
        }
コード例 #9
0
        public void Update()
        {
            var filepath = "Update";


            var context = new StorageContext <MyDataItem>(filepath, "Name");

            System.Threading.Tasks.Parallel.For(0, 10, (i) => {
                var item  = new MyDataItem();
                item.Name = "Jack" + i;
                context.Add(item);
            });

            if (context.Count != 10)
            {
                throw new Exception("数量不对");
            }

            var obj = context.FirstOrDefault(m => m.Name == "Jack5");

            obj.Company = "abc";
            context.Update(obj);

            context.Dispose();



            context = new StorageContext <MyDataItem>(filepath, "Name");
            if (context.Count != 10)
            {
                throw new Exception("数量不对");
            }

            obj = context.FirstOrDefault(m => m.Name == "Jack5");
            if (obj.Company != "abc")
            {
                throw new Exception("数据错误");
            }

            System.IO.File.Delete(filepath);
        }
コード例 #10
0
        public void Add()
        {
            var filepath = "Add";


            var context = new StorageContext <MyDataItem>(filepath, "Name");

            System.Threading.Tasks.Parallel.For(0, 10000, (i) => {
                var item  = new MyDataItem();
                item.Name = "Jack" + i;
                context.Add(item);
            });

            if (context.Count != 10000)
            {
                throw new Exception("数量不对");
            }

            context.Dispose();

            context = new StorageContext <MyDataItem>(filepath, "Name");
            if (context.Count != 10000)
            {
                throw new Exception("数量不对");
            }

            for (int i = 0; i < 10000; i++)
            {
                if (context.Any(m => m.Name == "Jack" + i) == false)
                {
                    throw new Exception("没有这个对象");
                }
            }

            System.IO.File.Delete(filepath);
        }