/// <summary> /// The statistics related to the variables and computations in this block /// </summary> public Dictionary <string, string> GetStatistics() { var stats = new Dictionary <string, string>(); var inputVarsTotalCount = _inputVariables.Count; var inputVarsUsedCount = _inputVariables.Count(inputVar => inputVar.IsUsed); var inputVarsUnUsedCount = inputVarsTotalCount - inputVarsUsedCount; stats.Add("Used Input Variables: ", inputVarsUsedCount.ToString()); stats.Add("Unused Input Variables: ", inputVarsUnUsedCount.ToString()); stats.Add("Total Input Variables: ", inputVarsTotalCount.ToString()); var tempVarsCount = TempVariables.Count(); var tempVarsSubExprCount = TempVariables.Count(item => item.IsFactoredSubExpression); var tempVarsNonSubExprCount = tempVarsCount - tempVarsSubExprCount; stats.Add("Common Subexpressions Temp Variables: ", tempVarsSubExprCount.ToString()); stats.Add("Generated Temp Variables: ", tempVarsNonSubExprCount.ToString()); stats.Add("Total Temp Variables: ", tempVarsCount.ToString()); stats.Add("Total Output Variables: ", OutputVariables.Count().ToString()); stats.Add("Total Computed Variables: ", ComputedVariables.Count.ToString()); stats.Add("Target Temp Variables: ", TargetTempVarsCount.ToString()); var computationsCountTotal = ComputedVariables .Select(computedVar => computedVar.RhsExpr.ComputationsCount) .Sum(); var computationsCountAverage = computationsCountTotal / (double)ComputedVariables.Count; stats.Add("Avg. Computations Count: ", computationsCountAverage.ToString("0.000")); stats.Add("Total Computations Count: ", computationsCountTotal.ToString()); var memreadsCountTotal = ComputedVariables .Select(computedVar => computedVar.RhsVariablesCount) .Sum(); var memreadsCountAverage = memreadsCountTotal / (double)ComputedVariables.Count; stats.Add("Avg. Memory Reads: ", memreadsCountAverage.ToString("0.000")); stats.Add("Total Memory Reads: ", memreadsCountTotal.ToString()); return(stats); }
/// <summary> /// The statistics related to the variables and computations in this block as a single string /// </summary> /// <returns></returns> public string GetStatisticsReport() { var s = new StringBuilder(); var inputVarsTotalCount = _inputVariables.Count; var inputVarsUsedCount = _inputVariables.Count(inputVar => inputVar.IsUsed); var inputVarsUnUsedCount = inputVarsTotalCount - inputVarsUsedCount; s.Append("Input Variables: ") .Append(inputVarsUsedCount) .Append(" used, ") .Append(inputVarsUnUsedCount) .Append(" not used, ") .Append(inputVarsTotalCount) .AppendLine(" total.") .AppendLine(); var tempVarsCount = TempVariables.Count(); var tempVarsSubExprCount = TempVariables.Count(item => item.IsFactoredSubExpression); var tempVarsNonSubExprCount = tempVarsCount - tempVarsSubExprCount; s.Append("Temp Variables: ") .Append(tempVarsSubExprCount) .Append(" sub-expressions, ") .Append(tempVarsNonSubExprCount) .Append(" generated temps, ") .Append(tempVarsCount) .AppendLine(" total.") .AppendLine(); if (TargetTempVarsCount > 0) { s.Append("Target Temp Variables: ") .Append(TargetTempVarsCount) .AppendLine(" total.") .AppendLine(); } var outputVarsCount = OutputVariables.Count(); s.Append("Output Variables: ") .Append(outputVarsCount) .AppendLine(" total.") .AppendLine(); var computationsCountTotal = ComputedVariables .Select(computedVar => computedVar.RhsExpr.ComputationsCount) .Sum(); var computationsCountAverage = computationsCountTotal / (double)ComputedVariables.Count; s.Append("Computations: ") .Append(computationsCountAverage) .Append(" average, ") .Append(computationsCountTotal) .AppendLine(" total.") .AppendLine(); var memreadsCountTotal = ComputedVariables .Select(computedVar => computedVar.RhsVariablesCount) .Sum(); var memreadsCountAverage = memreadsCountTotal / (double)ComputedVariables.Count; s.Append("Memory Reads: ") .Append(memreadsCountAverage) .Append(" average, ") .Append(memreadsCountTotal) .AppendLine(" total.") .AppendLine(); s.Append("Memory Writes: ") .Append(ComputedVariables.Count) .AppendLine(" total.") .AppendLine(); return(s.ToString()); }