//What happens when you press Map Reduce, number represents how many threads. private void map_reduce_button_Click(object sender, EventArgs e) { try { resultsTextBox.Text = ""; //Clear current text in text box. threads = (int)threadsTextBox.Value; //Number of threads. var usageBytes0 = GC.GetTotalMemory(true); //Memory usage after GC and before processing. var watch = System.Diagnostics.Stopwatch.StartNew(); //Start a timer for calculations. Results res = MapReduce.MainMapReduceThread(processingData, threads); //Activate MapReduce watch.Stop(); //End timer for calculation var usageBytes = GC.GetTotalMemory(false) - usageBytes0; //Memory usage after processing/before GC. Minus previous memory. var elapsedMs = watch.ElapsedMilliseconds; //Get timer value resultsTextBox.Text = DataFunc.ResultsText(res); //Push results into Textbox resultsTextBox.Text += "Overall run time: " + elapsedMs + " miliseconds. \n"; resultsTextBox.Text += "Current memory usage: " + usageBytes / 1024 + " KB"; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//Construct - all calculations are done here using methods from DataFunc. public Results(DataTable pdt) { this.Weight = pdt.Rows.Count; //How many lines table has, for usage in comparison for average (weight of result). this.YearlyAvg = DataFunc.TotalYearlyAvg(pdt); //Calculate it here, this is not an array so one line is enough. int[] bestYearResultsArray = DataFunc.BestYear(pdt); //Calculate result array once for usage in the next lines. this.BestYear = bestYearResultsArray[0]; this.BestYearAmount = bestYearResultsArray[1]; int[] bestMonthResultsArray = DataFunc.BestMonthAndItsYear(pdt); //Calculate result array once for usage in the next lines. this.BestMonthIndex = bestMonthResultsArray[0]; this.BestMonth = monthNames[BestMonthIndex]; this.BestMonthYear = bestMonthResultsArray[1]; this.BestMonthAmount = bestMonthResultsArray[2]; int[] worstYearResultsArray = DataFunc.WorstYear(pdt); //Calculate result array once for usage in the next lines. this.WorstYear = DataFunc.WorstYear(pdt)[0]; this.WorstYearAmount = DataFunc.WorstYear(pdt)[1]; int[] worstMonthResultsArray = DataFunc.WorstMonthAndItsYear(pdt); //Calculate result array once for usage in the next lines. this.WorstMonthIndex = worstMonthResultsArray[0]; this.WorstMonth = monthNames[WorstMonthIndex]; this.WorstMonthYear = worstMonthResultsArray[1]; this.WorstMonthAmount = worstMonthResultsArray[2]; int[] bestSeasonResultArray = DataFunc.BestSeasonAndItsYear(pdt); //Calculate result array once for usage in the next lines. this.BestSeasonIndex = bestSeasonResultArray[0]; this.BestSeason = seasonNames[BestSeasonIndex]; this.BestSeasonYear = bestSeasonResultArray[1]; this.BestSeasonAmount = bestSeasonResultArray[2]; int[] worstSeasonResultArray = DataFunc.WorstSeasonAndItsYear(pdt); //Calculate result array once for usage in the next lines. this.WorstSeasonIndex = worstSeasonResultArray[0]; this.WorstSeason = seasonNames[WorstSeasonIndex]; this.WorstSeasonYear = worstSeasonResultArray[1]; this.WorstSeasonAmount = worstSeasonResultArray[2]; }