Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const string clientAccount = "3801000BL040264";
- bool firstRun = true;
- var minMax = OracleInternetBank.OracleDb.Instance.GetMinMax(clientAccount);
- var rawList = OracleInternetBank.OracleDb.Instance.ListBolcardInvoiceLinq(clientAccount);
- for (int j = 0; j < 5; j++)
- {
- var startDate = DateTime.Now.AddYears((-3 - j));
- var endDate = DateTime.Now;
- GetForeachResult(clientAccount, rawList, minMax);
- if (firstRun)
- {
- for (int i = 0; i < 5; i++)
- {
- GetForeachResult(clientAccount, rawList, minMax);
- }
- Console.WriteLine("Warm up finish");
- }
- var timerStart = DateTime.Now;
- for (int i = 0; i < 100; i++)
- {
- GetForeachResult(clientAccount, rawList, minMax);
- }
- Console.WriteLine(String.Format("Foreach: {0}", (DateTime.Now - timerStart).Milliseconds));
- if (firstRun)
- {
- for (int i = 0; i < 5; i++)
- {
- GetLinqResult(clientAccount, rawList, minMax);
- }
- Console.WriteLine("Warm up finish");
- }
- timerStart = DateTime.Now;
- for (int i = 0; i < 100; i++)
- {
- GetLinqResult(clientAccount, rawList, minMax);
- }
- Console.WriteLine(String.Format("LINQ: {0}", (DateTime.Now - timerStart).Milliseconds));
- firstRun = false;
- }
- Console.WriteLine("Finished.");
- Console.ReadKey();
- private static void GetLinqResult(string clientAccount, IEnumerable<InvoiceInfo> rawList, InvoiceMinMax minMax)
- {
- var rawUnpeedList = rawList.Where(info => info.Flag == 0);
- var rawPaedList = rawList.Where(info => info.Flag > 0);
- var digestList = new List<InvoicePeriod>();
- var curDate = minMax.Min;
- do
- {
- var list = rawUnpeedList.Where(info => info.Invoice == curDate);
- var total = 0f;
- var invoiceInfos = list as IList<InvoiceInfo> ?? list.ToList();
- if (invoiceInfos.Count > 0)
- {
- digestList.Add(new InvoicePeriod(invoiceInfos.OrderBy(info => info.TranshDate).ToList(), curDate, total));
- }
- curDate = curDate.AddMonths(1);
- } while (curDate <= minMax.Max);
- var payeedList = new List<InvoicePeriod>();
- curDate = minMax.Min;
- do
- {
- var list = rawPaedList.Where(info => info.Invoice == curDate);
- var total = 0f;
- var invoiceInfos = list as IList<InvoiceInfo> ?? list.ToList();
- if (invoiceInfos.Count > 0)
- {
- payeedList.Add(new InvoicePeriod(invoiceInfos.OrderBy(info => info.TranshDate).ToList(), curDate, total));
- }
- curDate = curDate.AddMonths(1);
- } while (curDate <= minMax.Max);
- }
- private static void GetForeachResult(string clientAccount, IEnumerable<InvoiceInfo> rawList, InvoiceMinMax minMax)
- {
- var rawUnpayedList = new List<InvoiceInfo>();
- var rawPayedList = new List<InvoiceInfo>();
- foreach (var row in rawList)
- {
- if (row.Flag == 0)
- {
- rawUnpayedList.Add(row);
- }
- }
- foreach (var row in rawList)
- {
- if (row.Flag > 0)
- {
- rawPayedList.Add(row);
- }
- }
- var unpayedList = new List<InvoicePeriod>();
- var curDate = minMax.Min;
- do
- {
- var list = new List<InvoiceInfo>();
- foreach (var row in rawUnpayedList)
- {
- if (row.Invoice == curDate)
- {
- list.Add(row);
- }
- }
- var total = 0f;
- if (list.Count > 0)
- {
- list.Sort((p1, p2) => p1.TranshDate.CompareTo(p2.TranshDate)
- );
- unpayedList.Add(new InvoicePeriod(list, curDate, total));
- }
- curDate = curDate.AddMonths(1);
- } while (curDate <= minMax.Max);
- var payeedList = new List<InvoicePeriod>();
- curDate = minMax.Min;
- do
- {
- var list = new List<InvoiceInfo>();
- foreach (var row in rawPayedList)
- {
- if (row.Invoice == curDate)
- {
- list.Add(row);
- }
- }
- var total = 0f;
- if (list.Count > 0)
- {
- list.Sort((p1, p2) => p1.TranshDate.CompareTo(p2.TranshDate)
- );
- payeedList.Add(new InvoicePeriod(list, curDate, total));
- }
- curDate = curDate.AddMonths(1);
- } while (curDate <= minMax.Max);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement