Пример #1
0
        public void Profile_Enumerations_Using_Nested_Loops()
        {
            var parents  = new LoggingEnumerable <Parent>(_parents, ParentsLog);
            var children = new LoggingEnumerable <Child>(_children, ChildrenLog);

            var codes = new List <int>();

            foreach (Parent parent in parents)
            {
                Guid parentId           = parent.Id;
                IEnumerable <Child> ptc = children.Where(x => x.ParentId == parentId);
                foreach (Child child in ptc)
                {
                    int hash = ComputeHash(child, parent);
                    codes.Add(hash);
                }
            }

            Console.WriteLine("{0} computations completed.", codes.Count);
            foreach (var kvp in _childrenLog)
            {
                Console.WriteLine("Children_{0}:{1}", kvp.Key, kvp.Value);
            }
            foreach (var kvp in _parentLog)
            {
                Console.WriteLine("Parent_{0}:{1}", kvp.Key, kvp.Value);
            }
        }
Пример #2
0
        public void Profile_Enumerations_Using_Linq_Join()
        {
            var parents  = new LoggingEnumerable <Parent>(_parents, ParentsLog);
            var children = new LoggingEnumerable <Child>(_children, ChildrenLog);

            IEnumerable <int> ptc = from p in parents
                                    join c in children
                                    on p.Id equals c.ParentId
                                    select ComputeHash(p, c);

            List <int> codes = ptc.ToList();

            Console.WriteLine("{0} computations completed.", codes.Count);
            foreach (var kvp in _childrenLog)
            {
                Console.WriteLine("Children_{0}:{1}", kvp.Key, kvp.Value);
            }
            foreach (var kvp in _parentLog)
            {
                Console.WriteLine("Parent_{0}:{1}", kvp.Key, kvp.Value);
            }
        }