Esempio n. 1
0
        /// <summary>
        /// for a given set, runs the filter and outputs the run time. attempts single thread, parallel, and custom threadpool
        /// of 1, 2, 4, 8 threads to compare results
        /// </summary>
        /// <param name="testData"></param>
        /// <param name="filter"></param>
        /// <param name="remarks"></param>
        public static void TestFilterTimes(List <IHasBits> testData, Func <IHasBits, bool> filter, string remarks)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("Tests starting for {0}.  {1} items" + Environment.NewLine, remarks, testData.Count);

            Tuple <string, long> bestPerf;

            var sw      = Stopwatch.StartNew();
            var newList = testData.FilterList(filter);

            sw.Stop();
            sb.AppendFormat("regular. elapsed ms {0}.  matched {1}" + Environment.NewLine, sw.ElapsedMilliseconds, newList.Count);
            bestPerf = new Tuple <string, long>("regular", sw.ElapsedMilliseconds);

            sw.Reset();
            sw.Start();
            newList = testData.FilterList_UsingParallel(filter);
            sw.Stop();
            sb.AppendFormat("parallel. elapsed ms {0}.  matched {1}" + Environment.NewLine, sw.ElapsedMilliseconds, newList.Count);
            if (sw.ElapsedMilliseconds < bestPerf.Item2)
            {
                bestPerf = new Tuple <string, long>("parallel", sw.ElapsedMilliseconds);
            }

            //newList.ForEach(x =>
            //{
            //    Debug.WriteLine("regular parallel match {0}", x.Bits.ToString());
            //});

            List <int> workerCounts = new List <int> {
                1, 2, 4, 8
            };

            foreach (var each in workerCounts)
            {
                sw.Reset();
                sw.Start();
                newList = testData.FilterList_UsingWorkers(filter, each);
                sw.Stop();
                sb.AppendFormat("{2} workers. elapsed ms {0}.  matched {1}" + Environment.NewLine, sw.ElapsedMilliseconds, newList.Count, each);
                if (sw.ElapsedMilliseconds < bestPerf.Item2)
                {
                    bestPerf = new Tuple <string, long>(each + " workers", sw.ElapsedMilliseconds);
                }
                //newList.ForEach(x =>
                //{
                //    Debug.WriteLine("match {0}", x.Bits.ToString());
                //});
            }

            sb.AppendFormat("best perf {0} {1}" + Environment.NewLine, bestPerf.Item1, bestPerf.Item2);

            Debug.Write(sb.ToString());
        }
Esempio n. 2
0
        /// <summary>
        /// for a given set, runs the filter and outputs the run time. attempts single thread, parallel, and custom threadpool
        /// of 1, 2, 4, 8 threads to compare results
        /// </summary>
        /// <param name="testData"></param>
        /// <param name="filter"></param>
        /// <param name="remarks"></param>
        public static void TestFilterTimes(List<IHasBits> testData, Func<IHasBits, bool> filter, string remarks)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("Tests starting for {0}.  {1} items" + Environment.NewLine, remarks, testData.Count);

            Tuple<string, long> bestPerf;

            var sw = Stopwatch.StartNew();
            var newList = testData.FilterList(filter);
            sw.Stop();
            sb.AppendFormat("regular. elapsed ms {0}.  matched {1}" + Environment.NewLine, sw.ElapsedMilliseconds, newList.Count);
            bestPerf = new Tuple<string, long>("regular", sw.ElapsedMilliseconds); 
            
            sw.Reset();
            sw.Start();
            newList = testData.FilterList_UsingParallel(filter);
            sw.Stop();
            sb.AppendFormat("parallel. elapsed ms {0}.  matched {1}" + Environment.NewLine, sw.ElapsedMilliseconds, newList.Count);
            if (sw.ElapsedMilliseconds < bestPerf.Item2)
                bestPerf = new Tuple<string, long>("parallel", sw.ElapsedMilliseconds);

            //newList.ForEach(x =>
            //{
            //    Debug.WriteLine("regular parallel match {0}", x.Bits.ToString());
            //});

            List<int> workerCounts = new List<int> { 1, 2, 4, 8 };
            foreach (var each in workerCounts)
            {
                sw.Reset();
                sw.Start();
                newList = testData.FilterList_UsingWorkers(filter, each);
                sw.Stop();
                sb.AppendFormat("{2} workers. elapsed ms {0}.  matched {1}" + Environment.NewLine, sw.ElapsedMilliseconds, newList.Count, each);
                if (sw.ElapsedMilliseconds < bestPerf.Item2)
                    bestPerf = new Tuple<string, long>(each + " workers", sw.ElapsedMilliseconds);
                //newList.ForEach(x =>
                //{
                //    Debug.WriteLine("match {0}", x.Bits.ToString());
                //});
            }

            sb.AppendFormat("best perf {0} {1}" + Environment.NewLine, bestPerf.Item1, bestPerf.Item2);

            Debug.Write(sb.ToString());
        }
Esempio n. 3
0
        public List <StoredObjectId> SearchIndex(Func <IHasBits, bool> filter)
        {
            Condition.Requires(filter).IsNotNull();
            var rv = new List <StoredObjectId>();

            var             items = this._storeOfIndices.GetAll <IndexedEntry>();
            List <IHasBits> list  = new List <IHasBits>();

            list.AddRange(items);

            var filtList = list.FilterList_UsingParallel(filter);

            filtList.WithEach(x =>
            {
                rv.Add((x as IndexedEntry).Id as StoredObjectId);
            });
            return(rv);
        }
Esempio n. 4
0
        public List<StoredObjectId> SearchIndex(Func<IHasBits, bool> filter)
        {
            Condition.Requires(filter).IsNotNull();
            var rv = new List<StoredObjectId>();

            var items = this._storeOfIndices.GetAll<IndexedEntry>();
            List<IHasBits> list = new List<IHasBits>();
            list.AddRange(items);

            var filtList = list.FilterList_UsingParallel(filter);
            filtList.WithEach(x =>
            {
                rv.Add((x as IndexedEntry).Id as StoredObjectId);
            });
            return rv;
        }