Continuing from our last post : VB Speed Test I
Lets get to the next section:
for( my $i=0; $i < scalar(@filenames); $i++) { # If we don't have any functions there is no point in writing out our declare or continuing with the file if ($one > 0)
{
if ($filenames[$i] =~ m/^\s*Attribute VB_Ext_KEY = \"Top_Level\" (\"Yes\"|\"No\")/)
{
print OUT $filenames[$i];
print OUT "Private Declare Function GetTickCount Lib \"kernel32\" \(\) As Long\n\n";
}
else
{
print OUT $filenames[$i];
}
So I found that on my particular setup when I inserted the Private Declare right at the beginning (I was expecting before the first function) there was in reality more lines we don't normally see. So in order to get around this I found that the above statement was the "last" line before we really started the "visible" text in Visual Basic. So we insert the line after that.
So next we go with the section we insert the code:
if ($filenames[$i] =~ m/^\s*(Public|Private) (Function|Sub)/)
{
$insert = "\n'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''\n";
print OUT $insert;
$insert = "'The Function will be timed.\n\n";
print OUT $insert;
# we found a function so let's "push" a "dim" line to it that matches the name of the function with _timer on it.
@funcLine = split(/\s+/, $filenames[$i]);
@function = split(/\(/, $funcLine[2]);
$firstVar = @function[0] . "_start_timer";
$insert = "\nDim $firstVar as Long\n";
#pump out insert
print OUT $insert;
$secondVar = @function[0] . "_stop_timer";
$insert = "Dim $secondVar as Long\n";
#pump out insert
print OUT $insert;
$thirdVar = @function[0] . "_final";
$insert = "Dim $thirdVar as Long\n\n";
#pump out insert
print OUT "Dim Tmrfso As New Scripting.FileSystemObject\n";
print OUT "Dim TmrfileWriter As TextStream\n";
print OUT $insert;
$insert = "$firstVar = GetTickCount()\n\n";
#pump out insert
print OUT $insert;
$insert = "'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''\n\n";
print OUT $insert;
} # end if
What we have is the text that we put at the beginning of the function, this will initialize the variables, read the current tick count. The nice thing is that the name of the function varibles we created are based on the name of the function they are in, what that means is when we print out our information, we'll be able to determine exactly what functions have been run,
Next post we'll discuss the items at the end of the functions as well as analyzing the data.