Optimization performance winform app
is there any way how can I improve the performance of my app by some utilits? I am writting app in C# with .Net framework 3.5 and it is app which shows logs files which has many lines (they are text files about 200MBs) and It can has 500MB RAM memory and about 10s loaded. Can I get some of these performance down? Ofcourse it can be doing by better code but I saw something with NGEN, GAC, ... Can this help too for my kind of app? Thanks
Edit
Example of log file:
110331 052205 4969 [DB] fbba246f-bbe8-43b0-b8ca-f53bb90e8b51 Q SELECT GRAFIKON.ID,GRAFIKON.NADRAZENYGRAFIKONID,GRAFIKON.PLATNOSTOD,GRAFIKON.PLATNOSTDO,GRAFIKON.OBJEDNAVANIOD,GRAFIKON.OBJEDNAVANIDO,GRAFIKON.NAZEV,GRAFIKON.PROOBJEDNAVANI,GRAFIKON.ARCHIV,GRAFIKON.UZAVREN,GRAFIKON_0.Nazev,GRAFIKON_1.PlatnostOd FROM GRAFIKON LEFT OUTER JOIN GRAFIKON GRAFIKON_0 ON GRAFIKON.NADRAZENYGRAFIKONID = GRAFIKON_0.Id LEFT OUTER JOIN GRAFIKON GRAFIKON_1 ON GRAFIKON.NADRAZENYGRAFIKONID = GRAFIKON_1.Id WHERE (GRAFIKON.PROOBJEDNAVANI = 1)
110331 052205 6062 [DB] fbba246f-bbe8-43b0-b8ca-f53bb90e8b51 Q 0s 109ms
110331 052205 6375 [DB] acdbcdb6-aa3a-460a-a323-0be7c4512c14 Q SELECT NASTAVENI.ID,NASTAVENI.KLIC,NASTAVENI.HODNOTA,NASTAVENI.INFO,NASTAVENI.SKUPINA,NASTAVENI.TEXTAREA FROM NASTAVENI WHERE (NASTAVENI.KLIC = 'ARTICLE_AFTER_OPEN')
110331 052205 6688 [DB] acdbcdb6-aa3a-460a-a323-0be7c4512c14 Q 0s 31ms
110331 052205 7625 [DB] 9fd6ec6b-4844-44fe-8367-26c580ca8493 Q SELECT NASTAVENI.ID,NASTAVENI.KLIC,NASTAVENI.HODNOTA,NASTAVENI.INFO,NASTAVENI.SKUPINA,NASTAVENI.TEXTAREA FROM NASTAVENI WHERE (NASTAVENI.KLIC = 'GRAPHICON_CLOSED_SMS_TEXT')
110331 052205 7625 [DB] 9fd6ec6b-4844-44fe-8367-26c580ca8493 Q < 15ms
110331 065945 6813 [DB] 6387c3a4-33a5-4dfd-92d3-f4a8d00c910d Q SELECT GRAFIKON.ID,GRAFIKON.NADRAZENYGRAFIKONID,GRAFIKON.PLATNOSTOD,GRAFIKON.PLATNOSTDO,GRAFIKON.OBJEDNAVANIOD,GRAFIKON.OBJEDNAVANIDO,GRAFIKON.NAZEV,GRAFIKON.PROOBJEDNAVANI,GRAFIKON.ARCHIV,GRAFIKON.UZAVREN,GRAFIKON_0.Nazev,GRAFIKON_1.PlatnostOd FROM GRAFIKON LEFT OUTER JOIN GRAFIKON GRAFIKON_0 ON GRAFIKON.NADRAZENYGRAFIKONID = GRAFIKON_0.Id LEFT OUTER JOIN GRAFIKON GRAFIKON_1 ON GRAFIKON.NADRAZENYGRAFIKONID = GRAFIKON_1.Id WHERE (GRAFIKON.PROOBJEDNAVANI = 1)
1103开发者_Go百科31 065945 7438 [DB] 6387c3a4-33a5-4dfd-92d3-f4a8d00c910d Q 0s 62ms
First 12 numbers are date and time (then it is ms I can drop it), then modul, information, Q as query and then next information or time how long it takes to execute. And this is my code:
private Record GetRecordFromString(string strWithRecord)
{
Record newRecord = new Record();
try
{
if (strWithRecord.Length < 24)
{
newRecord.Prikaz = strWithRecord;
return newRecord;
}
if(!CheckIfFirstCharsAreDateTime(strWithRecord))
{
newRecord.Prikaz = strWithRecord;
return newRecord;
}
newRecord.Datum = ChangeDateFormat(strWithRecord.Substring(0, 6));
newRecord.Cas = ChangeTimeFormat(strWithRecord.Substring(7, 6));
strWithRecord = strWithRecord.Remove(0, 20);
int tempInt = strWithRecord.IndexOf(']');
newRecord.Modul = strWithRecord.Substring(0, tempInt);
strWithRecord = strWithRecord.Remove(0, tempInt + 2);
if (newRecord.Modul.StartsWith("DB"))
{
if (Char.IsUpper(strWithRecord[0]))
{
newRecord.Informace = strWithRecord;
}
else
{
tempInt = strWithRecord.IndexOf(' ');
newRecord.Informace = strWithRecord.Substring(0, tempInt);
strWithRecord = strWithRecord.Remove(0, tempInt + 1);
tempInt = strWithRecord.IndexOf(' ');
newRecord.Priznak = strWithRecord.Substring(0, tempInt);
strWithRecord = strWithRecord.Remove(0, tempInt + 1);
newRecord.Prikaz = strWithRecord;
}
}
else
{
newRecord.Informace = strWithRecord;
}
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
return newRecord;
}
private bool CheckIfFirstCharsAreDateTime(string stringToCheck)
{
if (!Char.IsNumber(stringToCheck[0]) || !Char.IsNumber(stringToCheck[1]) || !Char.IsNumber(stringToCheck[2]) || !Char.IsNumber(stringToCheck[3]) || !Char.IsNumber(stringToCheck[4]) || !Char.IsNumber(stringToCheck[5]) || !Char.IsWhiteSpace(stringToCheck[6]) || !Char.IsNumber(stringToCheck[7]) || !Char.IsNumber(stringToCheck[8]) || !Char.IsNumber(stringToCheck[9]) || !Char.IsNumber(stringToCheck[10]) || !Char.IsNumber(stringToCheck[11]) || !Char.IsNumber(stringToCheck[12]))
{
return false;
}
return true;
}
private string ChangeDateFormat(string strWithDate)
{
try
{
if (String.IsNullOrEmpty(strWithDate))
return "";
char[] arrayOfChars = strWithDate.ToCharArray();
strWithDate = arrayOfChars[4].ToString() + arrayOfChars[5].ToString() + "." + arrayOfChars[2].ToString() + arrayOfChars[3].ToString() + ".20" + arrayOfChars[0].ToString() + arrayOfChars[1].ToString();
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
return strWithDate;
}
private string ChangeTimeFormat(string strWithTime)
{
if (String.IsNullOrEmpty(strWithTime))
return "";
strWithTime = strWithTime.Insert(2, ":");
strWithTime = strWithTime.Insert(5, ":");
return strWithTime;
}
Edit2 Profiler file
NGEN only helps JIT performance; now, you can try that, but given your scenario it sounds to me like you are throttled on IO performance. The simplest "fix" I can suggest is: fit a faster disk (an SSD or something).
Of course, you aren't showing how exactly you are reading the files; I would suggest a StreamReader
and ReadLine()
, and only reading the data you actually want to display.
Preformance profiler for load time and memory profiler for memory usage.
http://www.red-gate.com/
They have both tools and a free trial. Nothing more can be said, as your question is without code, so reply without code :)
This article may be of some use to you regarding how to speed up Winforms application load time:
Improving Application Startup Time
If you are loading the entire 200MB text file into memory on load however I'm not sure how much that will help - you should try to find a way to avoid loading large files into memory but how you do that will depend completley on how your application works.
If you have to deal with such large datasets, you have to think about perceived performance. For instance, why not do all the work on a background thread using the BackgroundWorker component and use it's OnProgress event to let the user know its progress.
NGEN and other tricks will only take you so far (really not that far) - you have to realize that you need a different approach.
精彩评论