static void TestInternal(int loopCount)
        {
            var db = new SQLiteStorage <MockObjectGen.MockUser> (filename);

            db.Clear();
            db.Shrink();
            ServiceStack.Text.JsConfig.DateHandler = ServiceStack.Text.JsonDateHandler.ISO8601;

            logger.Info(String.Format("Initializing {0} items", loopCount));
            var list = MockObjectGen.GetTestUserDefinition(loopCount, "group name test", true).ToList();

            int len   = loopCount / 50;
            int start = list.Count - (len + 1);

            if (start < 0)
            {
                start = 0;
            }
            len = start + len;
            if (len > list.Count)
            {
                len = list.Count - start;
            }

            using (Benchmark.Start("Insertion test {0}", list.Count))
            {
                foreach (var i1 in list)
                {
                    db.Set(i1.Login, i1);
                }
            }

            using (Benchmark.Start("Get All with index {0}", list.Count))
            {
                foreach (var i in list)
                {
                    db.Get(i.Login).Count();
                }
            }

            using (Benchmark.Start("Get All with linq filter {0} x {1}", (len - start), loopCount))
            {
                for (int i = start; i < len; i++)
                {
                    db.Get().Where(u => u.Login == list[i].Login).Count();
                }
            }

            using (Benchmark.Start("Parallel Set And Get Test for some keys ({0})", loopCount / 10))
            {
                var forRes = System.Threading.Tasks.Parallel.ForEach(list.Skip(loopCount / 10).Take(loopCount / 10),
                                                                     u =>
                {
                    db.Set(u.Login, u);
                    db.Get(u.Login).First();
                    db.Get(u.Login).Count();
                });
                if (!forRes.IsCompleted)
                {
                    throw new Exception("Parallel execution error!");
                }
            };

            db.Clear();
            db.Shrink();
        }
Пример #2
0
        internal static void TestInternal(int loopCount)
        {
            logger.Info("Initializing 10.000 items");
            var list = MockObjectGen.GetTestUserDefinition(10000, "group name test", true).ToList();
            var txt  = new string[list.Count];

            using (Benchmark.Start("JsonSpeedTest.Newtonsoft.Serialize"))
            {
                for (var i = 0; i < loopCount; i++)
                {
                    for (int i1 = 0; i1 < list.Count; i1++)
                    {
                        txt[i1] = Newtonsoft.Json.JsonConvert.SerializeObject(list[i1]);
                    }
                }
            }

            using (Benchmark.Start("JsonSpeedTest.Newtonsoft.Deserialize"))
            {
                for (var i = 0; i < loopCount; i++)
                {
                    for (int i1 = 0; i1 < txt.Length; i1++)
                    {
                        Newtonsoft.Json.JsonConvert.DeserializeObject <PerformanceTest.MockObjectGen.MockUser> (txt[i1]);
                    }
                }
            }

            using (Benchmark.Start("JsonSpeedTest.fastJSON.Serialize"))
            {
                for (var i = 0; i < loopCount; i++)
                {
                    for (int i1 = 0; i1 < list.Count; i1++)
                    {
                        txt[i1] = fastJSON.JSON.Instance.ToJSON(list[i1]);
                    }
                }
            }

            using (Benchmark.Start("JsonSpeedTest.fastJSON.Deserialize"))
            {
                for (var i = 0; i < loopCount; i++)
                {
                    for (int i1 = 0; i1 < txt.Length; i1++)
                    {
                        fastJSON.JSON.Instance.ToObject <PerformanceTest.MockObjectGen.MockUser> (txt[i1]);
                    }
                }
            }

            using (Benchmark.Start("JsonSpeedTest.ServiceStack.Serialize"))
            {
                for (var i = 0; i < loopCount; i++)
                {
                    for (int i1 = 0; i1 < list.Count; i1++)
                    {
                        txt[i1] = ServiceStack.Text.JsonSerializer.SerializeToString(list[i1]);
                    }
                }
            }

            using (Benchmark.Start("JsonSpeedTest.ServiceStack.Deserialize"))
            {
                for (var i = 0; i < loopCount; i++)
                {
                    for (int i1 = 0; i1 < txt.Length; i1++)
                    {
                        ServiceStack.Text.JsonSerializer.DeserializeFromString <PerformanceTest.MockObjectGen.MockUser> (txt[i1]);
                    }
                }
            }

            using (Benchmark.Start("JsonSpeedTest.ServiceStack.Serialize [JSV]"))
            {
                for (var i = 0; i < loopCount; i++)
                {
                    for (int i1 = 0; i1 < list.Count; i1++)
                    {
                        txt[i1] = ServiceStack.Text.TypeSerializer.SerializeToString(list[i1]);
                    }
                }
            }

            using (Benchmark.Start("JsonSpeedTest.ServiceStack.Deserialize [JSV]"))
            {
                for (var i = 0; i < loopCount; i++)
                {
                    for (int i1 = 0; i1 < txt.Length; i1++)
                    {
                        ServiceStack.Text.TypeSerializer.DeserializeFromString <PerformanceTest.MockObjectGen.MockUser> (txt[i1]);
                    }
                }
            }
        }