Пример #1
0
        private static void SimpleNinjaCompiledQuery()
        {
            using (var context = new nob.NinjaObjectContext())
            {
                var oldninjas = s_compiledNinjaQuery.Invoke(context, new DateTime(1982, 1, 1));

                foreach (nob.Ninja ninja in oldninjas)
                {
                    Console.Out.WriteLine(ninja.Name);
                }
            }
        }
Пример #2
0
        private static void CompiledQueryPerformanceTest()
        {
            for (var j = 0; j < 5; j++)
            {
                using (var context = new nob.NinjaObjectContext())
                {
                    var start = DateTime.Now;
                    for (var i = 0; i < 10000; i++)
                    {
                        var result1 = s_compiledNinjaQuery.Invoke(context, new DateTime(1982, 1, 1));
                    }
                    double ms = (DateTime.Now - start).TotalMilliseconds;
                    Console.Out.WriteLine("Compiled query : " + ms.ToString() + "ms");
                }

                using (var ctx = new nob.NinjaObjectContext())
                {
                    var start = DateTime.Now;
                    var date  = new DateTime(1982, 1, 1);
                    for (var i = 0; i < 10000; i++)
                    {
                        var result2 = from ninja in ctx.Ninjas
                                      where ninja.DateOfBirth < date
                                      select ninja;
                    }
                    double ms = (DateTime.Now - start).TotalMilliseconds;
                    Console.Out.WriteLine("Non-Compiled query : " + ms.ToString() + "ms");
                }

                using (var ctx = new NinjaContext())
                {
                    var start = DateTime.Now;
                    var date  = new DateTime(1982, 1, 1);
                    for (var i = 0; i < 10000; i++)
                    {
                        var result2 = from ninja in ctx.Ninjas
                                      where ninja.DateOfBirth < date
                                      select ninja;
                    }
                    double ms = (DateTime.Now - start).TotalMilliseconds;
                    Console.Out.WriteLine("DbContext : " + ms.ToString() + "ms");
                }

                Console.Out.WriteLine("#######################");
            }
        }