M
mp
I'm using streamreader to open text files
I then look at each character in the file to detect certain patterns
it took 253 seconds
to parse 748 files
containing
563302 characters
then i commented out a few debug.print statements (which were called for
each file of course)
the time went down to 421 milliseconds
is that a normal impact from debug.print?
does that (421 milliseconds) sound like a reasonable amount of time to read
those characters?
or does it sound like further time optimizations should be sought out?
thanks
mark
in wpf form
private void button3_Click(object sender, RoutedEventArgs e)
{
int timein = Environment.TickCount;
int numFiles=0;
int sizeFiles = 0;
SortedDictionary<string, List<string>> defunsThisFolder = new
SortedDictionary<string, List<string>>();
string path = "C:\\0\\0code\\lisp\\newformat";
DirectoryInfo root = new DirectoryInfo(path);
var fileQuery = from fileInfo in
root.EnumerateFiles("*.lsp")
select fileInfo;
string FullName;
foreach (var fileInfo in fileQuery)
{
numFiles++;
FullName = fileInfo.FullName;
this.Title = "Reading file " + FullName + " , Please
wait...";
cLispFile cf = new cLispFile(FullName);
cf.ReadFile();
sizeFiles = sizeFiles + cf.FileLength;
cf.ListDefuns();
defunsThisFolder.Add(FullName, cf.DefunList);
}
foreach (KeyValuePair<string, List<string>> kvp in
defunsThisFolder)
{
this.lbOrig.Items.Add (kvp.Key);
foreach (string s in kvp.Value)
this.lbOrig.Items.Add('\t' + s);
}
int timeout = Environment.TickCount;
int elapsed = timeout - timein;
this.Title = "checked " + numFiles.ToString() + " files in "
+ (elapsed).ToString() + " milliseconds (" + sizeFiles.ToString() + ")
characters";
}
in cLispFile:
public void ReadFile()
{
if (_FileNotFound == false)
{
try
{
using (StreamReader sr = File.OpenText(_fileName))
{
GetCommentsFromStreamReader(sr);
}
}
catch (Exception ex)
{
Debug.Print(ex.Message);
throw;
}
}
}
private void GetCommentsFromStreamReader(StreamReader sr)
{
String input;
while ((input = sr.ReadLine()) != null)
{
GetCommentFromLine(input);
}
}
private void GetCommentFromLine(string inputString)
{
char preceedingCharacter = '\0';
char beforepreceedingCharacter = '\0';
char currentCharacter;
StringBuilder currentquote = new StringBuilder();
StringBuilder sbCommentsThisLine = new StringBuilder();
StringBuilder sbCommentsStrippedThisLine = new StringBuilder();
//----------------------------------------------------------------
//unless it's a multi line comment,(which im not yet
implementing)
//then each line clears InComment flag
_amInComment = false;
//----------------------------------------------------------------
_fileLength=_fileLength+inputString.Length;
for (int CharPos = 0; CharPos < inputString.Length; CharPos++)
{
currentCharacter=inputString[CharPos];
if (_amInQuote != true)
{
//semi colon is only comment if not inside a quoted
string""
if (currentCharacter == comment)
{
_amInComment = true;
}
//only process quote that are not commented out
if (_amInComment != true)
{
SetQuoteState(currentCharacter, CharPos,
preceedingCharacter, beforepreceedingCharacter, ref _amInQuote);
}
}
else//amInQuote is true
{
currentquote.Append(currentCharacter);
SetQuoteState(currentCharacter, CharPos,
preceedingCharacter, beforepreceedingCharacter, ref _amInQuote);
}
if (_amInComment == true)
{
sbCommentsThisLine.Append(currentCharacter);
}
else
{
sbCommentsStrippedThisLine.Append(currentCharacter);
}
beforepreceedingCharacter = preceedingCharacter;
preceedingCharacter = currentCharacter;
}//end for
_sbCommentsStrippedThisFile.Append(sbCommentsStrippedThisLine.ToString());
_sbCommentsStrippedThisFile.Append(Environment.NewLine);
_sbCommentsThisFile.Append(sbCommentsThisLine.ToString());
_sbCommentsThisFile.Append(Environment.NewLine);
RaiseCommentDetectedEvent(new
CommentDetectedEventArgs(inputString, sbCommentsThisLine.ToString(),
sbCommentsStrippedThisLine.ToString()));
}
private void SetQuoteState(char currentCharacter, int charPos, char
preceedingCharacter, char beforePreceedingCharacter, ref Boolean _amInQuote)
{
if (currentCharacter == quote)
{
if (_amInQuote == true)
{
if (preceedingCharacter != backslash)
{
_amInQuote = false;
}
else if (preceedingCharacter == backslash)
{
//if char before preceedingchar is backslash
then backslash is backslashed
if (beforePreceedingCharacter == backslash )
{
_amInQuote = false;
}
}
}
else
{
_amInQuote = true;
}
}//if current char is quote
}
I then look at each character in the file to detect certain patterns
it took 253 seconds
to parse 748 files
containing
563302 characters
then i commented out a few debug.print statements (which were called for
each file of course)
the time went down to 421 milliseconds
is that a normal impact from debug.print?
does that (421 milliseconds) sound like a reasonable amount of time to read
those characters?
or does it sound like further time optimizations should be sought out?
thanks
mark
in wpf form
private void button3_Click(object sender, RoutedEventArgs e)
{
int timein = Environment.TickCount;
int numFiles=0;
int sizeFiles = 0;
SortedDictionary<string, List<string>> defunsThisFolder = new
SortedDictionary<string, List<string>>();
string path = "C:\\0\\0code\\lisp\\newformat";
DirectoryInfo root = new DirectoryInfo(path);
var fileQuery = from fileInfo in
root.EnumerateFiles("*.lsp")
select fileInfo;
string FullName;
foreach (var fileInfo in fileQuery)
{
numFiles++;
FullName = fileInfo.FullName;
this.Title = "Reading file " + FullName + " , Please
wait...";
cLispFile cf = new cLispFile(FullName);
cf.ReadFile();
sizeFiles = sizeFiles + cf.FileLength;
cf.ListDefuns();
defunsThisFolder.Add(FullName, cf.DefunList);
}
foreach (KeyValuePair<string, List<string>> kvp in
defunsThisFolder)
{
this.lbOrig.Items.Add (kvp.Key);
foreach (string s in kvp.Value)
this.lbOrig.Items.Add('\t' + s);
}
int timeout = Environment.TickCount;
int elapsed = timeout - timein;
this.Title = "checked " + numFiles.ToString() + " files in "
+ (elapsed).ToString() + " milliseconds (" + sizeFiles.ToString() + ")
characters";
}
in cLispFile:
public void ReadFile()
{
if (_FileNotFound == false)
{
try
{
using (StreamReader sr = File.OpenText(_fileName))
{
GetCommentsFromStreamReader(sr);
}
}
catch (Exception ex)
{
Debug.Print(ex.Message);
throw;
}
}
}
private void GetCommentsFromStreamReader(StreamReader sr)
{
String input;
while ((input = sr.ReadLine()) != null)
{
GetCommentFromLine(input);
}
}
private void GetCommentFromLine(string inputString)
{
char preceedingCharacter = '\0';
char beforepreceedingCharacter = '\0';
char currentCharacter;
StringBuilder currentquote = new StringBuilder();
StringBuilder sbCommentsThisLine = new StringBuilder();
StringBuilder sbCommentsStrippedThisLine = new StringBuilder();
//----------------------------------------------------------------
//unless it's a multi line comment,(which im not yet
implementing)
//then each line clears InComment flag
_amInComment = false;
//----------------------------------------------------------------
_fileLength=_fileLength+inputString.Length;
for (int CharPos = 0; CharPos < inputString.Length; CharPos++)
{
currentCharacter=inputString[CharPos];
if (_amInQuote != true)
{
//semi colon is only comment if not inside a quoted
string""
if (currentCharacter == comment)
{
_amInComment = true;
}
//only process quote that are not commented out
if (_amInComment != true)
{
SetQuoteState(currentCharacter, CharPos,
preceedingCharacter, beforepreceedingCharacter, ref _amInQuote);
}
}
else//amInQuote is true
{
currentquote.Append(currentCharacter);
SetQuoteState(currentCharacter, CharPos,
preceedingCharacter, beforepreceedingCharacter, ref _amInQuote);
}
if (_amInComment == true)
{
sbCommentsThisLine.Append(currentCharacter);
}
else
{
sbCommentsStrippedThisLine.Append(currentCharacter);
}
beforepreceedingCharacter = preceedingCharacter;
preceedingCharacter = currentCharacter;
}//end for
_sbCommentsStrippedThisFile.Append(sbCommentsStrippedThisLine.ToString());
_sbCommentsStrippedThisFile.Append(Environment.NewLine);
_sbCommentsThisFile.Append(sbCommentsThisLine.ToString());
_sbCommentsThisFile.Append(Environment.NewLine);
RaiseCommentDetectedEvent(new
CommentDetectedEventArgs(inputString, sbCommentsThisLine.ToString(),
sbCommentsStrippedThisLine.ToString()));
}
private void SetQuoteState(char currentCharacter, int charPos, char
preceedingCharacter, char beforePreceedingCharacter, ref Boolean _amInQuote)
{
if (currentCharacter == quote)
{
if (_amInQuote == true)
{
if (preceedingCharacter != backslash)
{
_amInQuote = false;
}
else if (preceedingCharacter == backslash)
{
//if char before preceedingchar is backslash
then backslash is backslashed
if (beforePreceedingCharacter == backslash )
{
_amInQuote = false;
}
}
}
else
{
_amInQuote = true;
}
}//if current char is quote
}