Hello ,
i am working on a section of a project, that parses Logs from Postgres Database Server.
The application is developed in C sharp Framework 4.0.
A log is produced and displayed on a DataGridView with the following columns
resultCode Statement Starttime Duration
XT001 select * from PizzaMade 01-02-2012 03:10:14 00:04:10
- there are many loglines with the sameformat.
- The Datagridview is filled from another loop by parsing a Textfile.
My work is to generate stats from the data available in Grid in the following format
Statement Count countpercent Occurs_on
select * from PizzaMade 3 1.42 01/02 at 03pm [00:04:10], 01/02 at 04 [00:01:04]
select id,qty,table from PizzaMade 12 5.12 ...........
so basically the stats reflect the following
- a) statement executed
- b) Count number of times it appears in a grid
- c) percentage of count which is basically the portion of totalcounts this statement occupies
- d) a concatenated string containing starttime,duration
» The stats are generated as Datatable first, using a for loop
foreach(DataGridViewRow dr in LogGrid.Rows)
{
// search in the Datatable if the statement is present
// if it is then add count , add starttime and duration to the column
// if not then add a newrow
}
» After populating the datatable , i use a loop to calculate the Totalcount
int totalcount = 0;
foreach (DataRow dtrow in StatTable.Rows)
{
totalcount = totalcount + Convert.ToInt32(dr["count"].ToString());
}
» After calculating the count, there is a loop to calculate the percentage
foreach (DataRow dtrow in StatTable.Rows)
{
dr["countpercent"] = (count/totalcount)*100;
}
Although everything seems ok, the whole method is sluggish with large number of rows.
- Can you please suggest methods to improve the performance.
thanks
arvind