protected void CompareSearch(List <MockItem> list, OptimizedCollection <MockItem> collection) { int key = new Random(new Random().Next(0, list.Count - 1)).Next(0, list.Count - 1); Watch.Reset(); var query = collection.Using <UniqueKeyQuery <MockItem, int> >(); Watch.Start(); var mockedInCollection = query.Get(key); Watch.Stop(); var elapsed4Collection = Watch.Elapsed; Watch.Reset(); Watch.Start(); var mockedInList = list.BinarySearch(new MockItem { Index = key }); Watch.Stop(); var elapsed4List = Watch.Elapsed; Console.WriteLine("For the list<T>, took {0} to get one item, \n FastLane took {1}.", elapsed4List, elapsed4Collection); }
/// <summary> /// Removes to all queries, the value node /// </summary> /// <param name="optmizedStructure"></param> /// <param name="node"></param> public virtual void RemoveNode(OptimizedCollection <TItem> @struct, ValueNode <TItem> item) { DeriveNewState(@struct); foreach (var query in Queries) { RemoveInEach(query, item); } }
public void Setup() { RightIndex = 0; Query = new UniqueKeyQuery <MockItem, int>() { SelectKey = item => item.Index }; Collection = new OptimizedCollection <MockItem>(Query); }
public override void Setup() { RightIndex = 0; Watch = new Stopwatch(); _query = new _Query() { SelectKey = item => item.IndexInBytes, KeyComparer = (one, other) => one.UnsafeCompareTo(other) }; Collection = new OptimizedCollection <MockItem>(_query); }
protected void CompareSearch(List <MockItem> list, OptimizedCollection <MockItem> collection) { var max = list.Count; Watch.Reset(); var query = collection.Using <UniqueKeyQuery <MockItem, int> >(); Watch.Start(); for (int i = 0; i < max; i++) { var mockedInCollection = query.Get(i); } Watch.Stop(); var elapsed4Collection = Watch.Elapsed; Watch.Reset(); Watch.Start(); for (int i = 0; i < max; i++) { var mockedInList = list.BinarySearch(new MockItem { Index = i }); } Watch.Stop(); var elapsed4List = Watch.Elapsed; //Watch.Reset(); //Watch.Start(); //for (int i = 0; i < max; i++) //{ // var mockedInList = list.FirstOrDefault(item => item.Index == i); //} //Watch.Stop(); var elapsed4ListLinq = Watch.Elapsed; Console.WriteLine("For the list<T>, took {0} to get all items, for FastLane took {1}.", elapsed4List, elapsed4Collection); //Console.WriteLine("For the list<T> with linq, took {0} to get all items, for FastLane took {1}.", // elapsed4ListLinq, elapsed4Collection); }
protected void CompareSearch(List <MockItem> list, OptimizedCollection <MockItem> collection) { var max = list.Count; Watch.Reset(); var query = collection.Using <_Query>(); Watch.Start(); for (int i = 0; i < max; i++) { var mockedInCollection = query.Get(BitConverter.GetBytes(i)); } Watch.Stop(); var elapsed4Collection = Watch.Elapsed; Watch.Reset(); Watch.Start(); for (int i = 0; i < max; i++) { var mockedInList = list.BinarySearch(new MockItem { Index = i }); } Watch.Stop(); var elapsed4List = Watch.Elapsed; Watch.Reset(); Watch.Start(); for (int i = 0; i < max; i++) { var mockedInList = list.First(item => item.Index == i); } Watch.Stop(); var elapsed4ListLinq = Watch.Elapsed; Console.WriteLine("For the list<T>, took {0} to get all items, for FastLane took {1}.", elapsed4List, elapsed4Collection); Console.WriteLine("For the list<T> with linq, took {0} to get all items, for FastLane took {1}.", elapsed4ListLinq, elapsed4Collection); }
protected void CompareSearch(SortedList <int, MockItem> list, OptimizedCollection <MockItem> collection) { var max = list.Count; Watch.Reset(); int i = 0; Watch.Start(); try { for (i = 1; i < max; i++) { var mockedInList = list[i]; } } catch { Console.WriteLine("index " + i); } Watch.Stop(); var elapsed4List = Watch.Elapsed; Watch.Reset(); var query = collection.Using <UniqueKeyQuery <MockItem, int> >(); Watch.Start(); for (i = 0; i < max; i++) { var mockedInCollection = query.Get(i); } Watch.Stop(); var elapsed4Collection = Watch.Elapsed; Console.WriteLine("For the SortedList<int, T>, took {0} to get one item, for FastLane took {1}.", elapsed4List, elapsed4Collection); }
protected void CompareSearch(SortedList <int, MockItem> list, OptimizedCollection <MockItem> collection) { int key = new Random(new Random().Next(0, list.Count - 1)).Next(0, list.Count - 1); Watch.Reset(); Watch.Start(); var mockedInList = list[key]; Watch.Stop(); var elapsed4List = Watch.Elapsed; Watch.Reset(); Watch.Start(); var mockedInCollection = collection.Using <UniqueKeyQuery <MockItem, int> >().Get(key); Watch.Stop(); var elapsed4Collection = Watch.Elapsed; Console.WriteLine("For the SortedList<int, T>, took {0} to get one item, for FastLane took {1}.", elapsed4List, elapsed4Collection); }
/// <summary> /// When inherited, derive a new state of that query /// </summary> protected abstract void DeriveNewState(OptimizedCollection <TItem> @struct);
protected override void DeriveNewState(OptimizedCollection <TItem> @struct) { NewState = UniqueKeyQueryCalculus.Calculate4UniqueKey(@struct.Count, MaxComparisons); }