static void Main(string[] args) { OrderedBag<Item> catalog = new OrderedBag<Item>(); Random random = new Random(); for (int i = 0; i < 50000; i++) { catalog.Add(new Item("item" + i, random.Next(0, int.MaxValue))); } var prices = catalog.FindAll(x => x.Price > 100 && x.Price < 150); for (int i = 0; i < 10000; i++) { int min = random.Next(0, int.MaxValue); int max = random.Next(min, int.MaxValue); prices = catalog.FindAll(x => x.Price > min && x.Price < max); } //print only the result of the last search becouse printing is very slow operation int count = 20; foreach (var item in prices) { Console.WriteLine("name:"+item.Name + "-> price:"+item.Price); count -= 1; if (count<=0) { break; } } }
static void Main(string[] args) { OrderedBag <Product> products = new OrderedBag <Product>(); Random random = new Random(); for (int i = 0; i < 50000; i++) { products.Add(new Product("item" + i, random.Next(0, int.MaxValue))); } var prices = products.FindAll(x => x.Price > 0); for (int i = 0; i < 10000; i++) { int min = random.Next(0, int.MaxValue); int max = random.Next(min, int.MaxValue); prices = products.FindAll(x => x.Price > min && x.Price < max); } int counter = 20; foreach (var item in prices) { if (counter != 0) { Console.WriteLine("Name: {0} Price: {1}", item.Name, item.Price); counter--; } } }
static void Main(string[] args) { OrderedBag<Item> catalog = new OrderedBag<Item>(); Random random = new Random(); for (int i = 0; i < 50000; i++) { catalog.Add(new Item("item" + i, random.Next(0, int.MaxValue))); } var prices = catalog.FindAll(x => x.Price > 100 && x.Price < 150); for (int i = 0; i < 10000; i++) { int min = random.Next(0, int.MaxValue); int max = random.Next(min, int.MaxValue); prices = catalog.FindAll(x => x.Price > min && x.Price < max); } //print only the result of the last search becouse printing is very slow operation int count = 20; foreach (var item in prices) { Console.WriteLine("name:"+item.Name + "-> price:"+item.Price); count -= 1; if (count<=0) { break; } } }
private static void Main() { OrderedBag <Product> catalog = new OrderedBag <Product>(); Random randomGenerator = new Random(); Stopwatch sw = new Stopwatch(); TimeSpan ts = new TimeSpan(); sw.Start(); for (int i = 0; i < 500000; i++) { var number = randomGenerator.Next(0, int.MaxValue); catalog.Add(new Product { Name = string.Format("Pencho{0}", number), Price = (decimal)Math.Sqrt(number) }); } sw.Stop(); ts = sw.Elapsed; Console.WriteLine("Time elapsed for adding: {0}s {1}ms", ts.Seconds, ts.Milliseconds); sw.Reset(); sw.Start(); var productsInPriceRange = catalog.FindAll(p => p.Price > 1000 && p.Price < 5000); sw.Stop(); ts = sw.Elapsed; Console.WriteLine("Time elapsed for searching: {0}s {1}ms", ts.Seconds, ts.Milliseconds); sw.Reset(); sw.Start(); for (int i = 0; i < 10000; i++) { int min = randomGenerator.Next(0, 1000); int max = randomGenerator.Next(1000, int.MaxValue); productsInPriceRange = catalog.FindAll(p => p.Price > min && p.Price < max); } sw.Stop(); ts = sw.Elapsed; Console.WriteLine("Time elapsed for searching 10 000 times in 500 000 records: {0}s {1}ms", ts.Seconds, ts.Milliseconds); var selection = productsInPriceRange.Take(20); foreach (var product in selection) { Console.WriteLine("{0} -> ${1}", product.Name, product.Price); } }
public static void Main() { OrderedBag<Product> catalog = new OrderedBag<Product>(); for (int i = 0; i < 500000; i++) { catalog.Add(new Product("Product" + i, GetRandomNumber(39,709))); } var prices = catalog.FindAll(x => x.Price > 200 && x.Price < 350); int count = 20; StringBuilder sb = new StringBuilder(); foreach (var product in prices) { sb.AppendFormat("name: {0} -> price {1}", product.Name, product.Price); sb.AppendLine(); count -= 1; if (count <= 0) { break; } } Console.WriteLine("Print results: "); Console.WriteLine(sb.ToString()); }
static void Main() { Console.WriteLine("Generating product's list..."); var produkts = new OrderedBag<Product>(); Random rnd = new Random(); for (int i = 0; i < 500000; i++) { int price = rnd.Next(1, 100001); string name = "product-" + i; Product product = new Product(name, price); produkts.Add(product); } Console.WriteLine("Searching 20 products in range 10257 - 11336 lv"); Predicate<Product> isProduktInRange = p => p.Price >= 10257 && p.Price <= 11336; var range = produkts.FindAll(isProduktInRange); int count = 0; foreach (var item in range) { Console.WriteLine(item); ++count; if (count == 20) { return; } } }
public Systeme GetSystem(string s) { foreach (Systeme sys in systemList) { if (sys.ClassId == s) { return(sys); } } return(systemList.FindAll(x => x.GetType().Name == s).GetEnumerator().Current); }
private static void FindInRange(OrderedBag <Product> bag, decimal firstRange, decimal secondRange) { List <Product> twenty = new List <Product>(); twenty = bag.FindAll(x => x.Price >= firstRange && x.Price <= secondRange).Take(20).ToList(); foreach (var item in twenty) { Console.Write(item + " "); } Console.WriteLine(); }
private static void FindInRange(OrderedBag<Product> bag, decimal firstRange, decimal secondRange) { List<Product> twenty = new List<Product>(); twenty = bag.FindAll(x => x.Price >= firstRange && x.Price <= secondRange).Take(20).ToList(); foreach (var item in twenty) { Console.Write(item + " "); } Console.WriteLine(); }
static void Main(string[] args) { OrderedBag<Product> products = new OrderedBag<Product>(); Random randomPrice = new Random(); Stopwatch timer = new Stopwatch(); timer.Start(); for (int i = 0; i < 500000; i++) { double price=randomPrice.NextDouble(); products.Add(new Product("someName"+i, price)); } double min = randomPrice.NextDouble(); double max = randomPrice.NextDouble(); for (int i = 0; i < 10000; i++) { products.FindAll(x => x.Price > min && x.Price < max).Take(20); } timer.Stop(); Console.WriteLine("Program executed in {0}.", timer.Elapsed); }