Esempio n. 1
0
        public bool ComplicatedLinqFast(Stopwatch watch, int repeatCount, int takeCount)
        {
            watch.Start();

            for (var i = 0; i < repeatCount; i++)
            {
                using (var db = new EFCoreContext(TrackChanges))
                {
                    var q =
                        (
                            from n1 in db.Narrow
                            join n2 in db.Narrow on new { n1.ID, n1.Field1 } equals new { n2.ID, n2.Field1 }
                            where n1.ID < 100 && n2.Field1 <= 50
                            group n1 by n1.ID into gr
                            select new
                    {
                        gr.Key,
                        Count = gr.Count()
                    }
                        )
                        .OrderBy(n1 => n1.Key)
                        .Skip(1)
                        .Take(takeCount);

                    foreach (var item in q)
                    {
                    }
                }
            }

            watch.Stop();

            return(true);
        }
Esempio n. 2
0
        public bool SimpleLinqQuery(Stopwatch watch, int repeatCount, int takeCount)
        {
            watch.Start();

            for (var i = 0; i < repeatCount; i++)
            {
                using (var db = new EFCoreContext(TrackChanges))
                {
                    var q =
                        (
                            from n1 in db.Narrow
                            where n1.ID < 100
                            select n1.ID
                        )
                        .Take(takeCount);

                    foreach (var item in q)
                    {
                    }
                }
            }

            watch.Stop();

            return(true);
        }
Esempio n. 3
0
        public async Task <bool> GetWideListAsync(Stopwatch watch, int repeatCount, int takeCount)
        {
            watch.Start();

            for (var i = 0; i < repeatCount; i++)
            {
                using (var db = new EFCoreContext(TrackChanges))
                    await db.WideLong.Take(takeCount).ForEachAsync(item => {});
            }

            watch.Stop();

            return(true);
        }
Esempio n. 4
0
        public bool GetSingleColumnSlow(Stopwatch watch, int repeatCount, int takeCount)
        {
            watch.Start();

            for (var i = 0; i < repeatCount; i++)
            {
                using (var db = new EFCoreContext(TrackChanges))
                    db.Narrow.Where(t => t.ID == 1).Select(t => t.ID).AsEnumerable().First();
            }

            watch.Stop();

            return(true);
        }
Esempio n. 5
0
        public async Task <bool> GetSingleColumnSlowAsync(Stopwatch watch, int repeatCount, int takeCount)
        {
            watch.Start();

            for (var i = 0; i < repeatCount; i++)
            {
                using (var db = new EFCoreContext(TrackChanges))
                    await db.Narrow.Where(t => t.ID == 1).Select(t => t.ID).FirstAsync();
            }

            watch.Stop();

            return(true);
        }
Esempio n. 6
0
        public bool ComplicatedLinqSlow(Stopwatch watch, int repeatCount, int takeCount, int nRows)
        {
            watch.Start();

            for (var i = 0; i < repeatCount; i++)
            {
                using (var db = new EFCoreContext(TrackChanges))
                {
                    var q =
                        (
                            from n in db.NarrowLong
                            join w in db.WideLong on n.Field1 equals w.Field1
                            where
                            n.ID >= 0 && n.ID <= nRows &&
                            !new[] { 0, 20, 50, 187635 }.Contains(w.Field1)
                            select new
                    {
                        n.ID,
                        w.Field1
                    }
                        )
                        .Union
                        (
                            from n in db.NarrowLong
                            join w in db.WideLong on n.Field1 equals w.Field1
                            where
                            n.ID >= 0 && n.ID <= nRows &&
                            !new[] { 0, 240, 500, 18635 }.Contains(w.Field1)
                            select new
                    {
                        n.ID,
                        w.Field1
                    }
                        )
                        .OrderByDescending(n1 => n1.Field1)
                        .Skip(1000)
                        .Take(takeCount);

                    foreach (var item in q)
                    {
                    }
                }
            }

            watch.Stop();

            return(true);
        }
Esempio n. 7
0
        public async Task <bool> GetNarrowListAsync(Stopwatch watch, int repeatCount, int takeCount)
        {
            var sql = GetNarrowListSql(takeCount);

            watch.Start();

            for (var i = 0; i < repeatCount; i++)
            {
                using (var db = new EFCoreContext(TrackChanges))
                    await db.NarrowLong.FromSql(sql).ForEachAsync(item => {});
            }

            watch.Stop();

            return(true);
        }
Esempio n. 8
0
        public bool GetWideList(Stopwatch watch, int repeatCount, int takeCount)
        {
            watch.Start();

            for (var i = 0; i < repeatCount; i++)
            {
                using (var db = new EFCoreContext(TrackChanges))
                    foreach (var item in db.WideLong.Take(takeCount))
                    {
                    }
            }

            watch.Stop();

            return(true);
        }
Esempio n. 9
0
        public async Task <bool> GetSingleColumnParamAsync(Stopwatch watch, int repeatCount, int takeCount)
        {
            watch.Start();

            using (var db = new EFCoreContext(TrackChanges))
                for (var i = 0; i < repeatCount; i++)
                {
                    var id = 1;
                    var p  = 2;
                    await db.Narrow.Where(t => t.ID == id && t.Field1 == p).Select(t => t.ID).FirstAsync();
                }

            watch.Stop();

            return(true);
        }
Esempio n. 10
0
        public bool GetSingleColumnParam(Stopwatch watch, int repeatCount, int takeCount)
        {
            watch.Start();

            using (var db = new EFCoreContext(TrackChanges))
                for (var i = 0; i < repeatCount; i++)
                {
                    var id = 1;
                    var p  = 2;
                    db.Narrow.Where(t => t.ID == id && t.Field1 == p).Select(t => t.ID).AsEnumerable().First();
                }

            watch.Stop();

            return(true);
        }
Esempio n. 11
0
        public async Task <bool> GetWideListAsync(Stopwatch watch, int repeatCount, int takeCount)
        {
            var query = EF.CompileAsyncQuery((EFCoreContext db, int top) =>
                                             db.WideLong.Take(top));

            watch.Start();

            for (var i = 0; i < repeatCount; i++)
            {
                using (var db = new EFCoreContext(TrackChanges))
                    await query(db, takeCount).ForEachAsync(item => {});
            }

            watch.Stop();

            return(true);
        }
Esempio n. 12
0
        public async Task <bool> GetSingleColumnFastAsync(Stopwatch watch, int repeatCount, int takeCount)
        {
            var query = EF.CompileAsyncQuery((EFCoreContext db) =>
                                             db.Narrow.Where(t => t.ID == 1).Select(t => t.ID).First());

            watch.Start();

            using (var db = new EFCoreContext(TrackChanges))
                for (var i = 0; i < repeatCount; i++)
                {
                    await query(db);
                }

            watch.Stop();

            return(true);
        }
Esempio n. 13
0
        public bool GetSingleColumnSlow(Stopwatch watch, int repeatCount, int takeCount)
        {
            var query = EF.CompileQuery((EFCoreContext db) =>
                                        db.Narrow.Where(t => t.ID == 1).Select(t => t.ID).First());

            watch.Start();

            for (var i = 0; i < repeatCount; i++)
            {
                using (var db = new EFCoreContext(TrackChanges))
                    query(db);
            }

            watch.Stop();

            return(true);
        }
Esempio n. 14
0
        public bool GetSingleColumnParam(Stopwatch watch, int repeatCount, int takeCount)
        {
            var query = EF.CompileQuery((EFCoreContext db, int id, int p) =>
                                        db.Narrow.Where(t => t.ID == id && t.Field1 == p).Select(t => t.ID).First());

            watch.Start();

            using (var db = new EFCoreContext(TrackChanges))
                for (var i = 0; i < repeatCount; i++)
                {
                    query(db, 1, 2);
                }

            watch.Stop();

            return(true);
        }
Esempio n. 15
0
        public bool GetNarrowList(Stopwatch watch, int repeatCount, int takeCount)
        {
            var sql = GetNarrowListSql(takeCount);

            watch.Start();

            for (var i = 0; i < repeatCount; i++)
            {
                using (var db = new EFCoreContext(TrackChanges))
                    foreach (var item in db.NarrowLong.FromSql(sql))
                    {
                    }
            }

            watch.Stop();

            return(true);
        }
Esempio n. 16
0
        public bool GetWideList(Stopwatch watch, int repeatCount, int takeCount)
        {
            var query = EF.CompileQuery((EFCoreContext db, int top) =>
                                        db.WideLong.Take(top));

            watch.Start();

            for (var i = 0; i < repeatCount; i++)
            {
                using (var db = new EFCoreContext(TrackChanges))
                    foreach (var item in query(db, takeCount))
                    {
                    }
            }

            watch.Stop();

            return(true);
        }
Esempio n. 17
0
        public bool GetSingleColumnParam(Stopwatch watch, int repeatCount, int takeCount)
        {
            watch.Start();

            using (var db = new EFCoreContext(TrackChanges))
            {
                for (var i = 0; i < repeatCount; i++)
                {
                    db.Narrow
                    .FromSql(GetParamSql,
                             new SqlParameter("@id", 1),
                             new SqlParameter("@p", 2))
                    .Select(t => t.ID).AsEnumerable().First();
                }
            }

            watch.Stop();

            return(true);
        }