public void PerformTimeTests()
        {
            const int noOfCalls = 1000;
            var       watch     = new Stopwatch();

            watch.Start();
            for (var i = 0; i < noOfCalls; i++)
            {
                var s =
                    List.Where(p => p.Name != "b")
                    .OrderBy(p => p.Name)
                    .ThenBy(p => p.Stars)
                    .Take(1)
                    .Skip(0)
                    .ToList();
            }
            watch.Stop();
            Console.WriteLine("Direct lambda for {0} calls took {1}ms.", noOfCalls, watch.ElapsedMilliseconds);

            watch.Restart();
            var ex = _qObject.BuildWhereExpression <Company>().Compile();

            for (var i = 0; i < noOfCalls; i++)
            {
                var s =
                    List.AsQueryable().Where(ex).AsQueryable().GetSortedPageAsList(_qObject.GridCriteria).ToList();
            }
            watch.Stop();
            Console.WriteLine("Call using cached 'where expression' for {0} calls took {1}ms.", noOfCalls,
                              watch.ElapsedMilliseconds);

            watch.Restart();
            for (var i = 0; i < noOfCalls; i++)
            {
                var s =
                    List.AsQueryable()
                    .Where(_qObject.BuildWhereExpression <Company>().Compile())
                    .AsQueryable()
                    .GetSortedPageAsList(_qObject.GridCriteria)
                    .ToList();
            }
            watch.Stop();
            Console.WriteLine("Call with 'where expression' compiled explicitly for {0} calls took {1}ms.", noOfCalls,
                              watch.ElapsedMilliseconds);


            watch.Restart();
            for (var i = 0; i < noOfCalls; i++)
            {
                var s =
                    List.AsQueryable()
                    .Where(_qObject.BuildWhereExpression <Company>())
                    .AsQueryable()
                    .GetSortedPageAsList(_qObject.GridCriteria)
                    .ToList();
            }
            watch.Stop();
            Console.WriteLine("Call with 'where expression' not compiled for {0} calls took {1}ms.", noOfCalls,
                              watch.ElapsedMilliseconds);
        }
Esempio n. 2
0
        public void PerformTimeTests()
        {
            const int noOfCalls = 1000;
            var       watch     = new Stopwatch();

            watch.Start();
            for (var i = 0; i < noOfCalls; i++)
            {
                var s =
                    _list.Where(p => p.Name.Contains("na") && p.Surname == "Gradinariu" && p.Age <= 10)
                    .OrderByDescending(p => p.Age)
                    .ThenBy(p => p.Name)
                    .ThenBy(p => p.Surname)
                    .Take(1)
                    .Skip(0)
                    .ToList();
            }
            watch.Stop();
            Console.WriteLine("Direct lambda for {0} calls took {1}ms.", noOfCalls, watch.ElapsedMilliseconds);

            watch.Restart();
            var ex = _qObject.BuildWhereExpression <Person>().Compile();

            for (var i = 0; i < noOfCalls; i++)
            {
                var s =
                    _list.AsQueryable().Where(ex).AsQueryable().GetSortedPageAsList(_qObject.GridCriteria).ToList();
            }
            watch.Stop();
            Console.WriteLine("Call using cached 'where expression' for {0} calls took {1}ms.", noOfCalls,
                              watch.ElapsedMilliseconds);

            watch.Restart();
            for (var i = 0; i < noOfCalls; i++)
            {
                var s =
                    _list.AsQueryable()
                    .Where(_qObject.BuildWhereExpression <Person>().Compile())
                    .AsQueryable()
                    .GetSortedPageAsList(_qObject.GridCriteria)
                    .ToList();
            }
            watch.Stop();
            Console.WriteLine("Call with 'where expression' compiled explicitly for {0} calls took {1}ms.", noOfCalls,
                              watch.ElapsedMilliseconds);


            watch.Restart();
            for (var i = 0; i < noOfCalls; i++)
            {
                var s =
                    _list.AsQueryable()
                    .Where(_qObject.BuildWhereExpression <Person>())
                    .AsQueryable()
                    .GetSortedPageAsList(_qObject.GridCriteria)
                    .ToList();
            }
            watch.Stop();
            Console.WriteLine("Call with 'where expression' not compiled for {0} calls took {1}ms.", noOfCalls,
                              watch.ElapsedMilliseconds);

            watch.Restart();
            for (var i = 0; i < noOfCalls; i++)
            {
                var s = _list.AsQueryable().GetQuery(_qObject).Skip(1).ToList();
            }
            watch.Stop();
            Console.WriteLine("Call with 'pure expression' trees for {0} calls took {1}ms.", noOfCalls,
                              watch.ElapsedMilliseconds);
        }