Tutorial Addendum on Perl - Allotment A - Cord Achievement
| |
This affiliate describes:
- How the two alotof accepted cord functions accomplish beneath altered environments.
- A Perl program to analysis the achievement of substr() and index().
- A Java program to analysis the achievement of substring() and indexOf().
Perl Analysis Program - SubstringTest.pl
I wrote the afterward program, SubstringTest.pl, in 1996 on a SunOS arrangement to analysis
the achievement of substr() and index() functions:
#- SubstringTest.pl
#- Absorb (c) 1996 by Dr. Yang
#
($numChar, $numTest) = @ARGV;
$numChar = 10 unless $numChar;
$numTest = 1 unless $numTest;
$baseString = &setString($numChar);
$subString = &setString($numChar);
$startTime = time();
$numMatch = 0;
for ($i=0; $i<$numTest; $i++) {
$numMatch = &test();
}
$endTime = time();
$totalTime = $startTime - $endTime;
$averageTime = $totalTime/$numTest;
print("Number of tests = $numTest
");
print("Number of characters = $numChar
");
print("Number of matches = $numMatch
");
print("Total time = $totalTime seconds
");
print("Average time = $averageTime seconds
");
exit;
sub setString {
local($size) = @_;
bounded $str = "";
local($i,$n,$c);
for ($i=0; $i<$size; $i++) {
$n = int(rand(96)) + 32;
$c = chr($n);
$str .= $c;
}
acknowledgment $str;
}
sub analysis {
local($i,$j,$l);
bounded $str = "";
bounded $num = 0;
bounded $pos = -1;
for ($i=0; $i<$numChar; $i++) {
$l = $i+1;
for ($j=0; $j<$numChar-$i; $j++) {
$str = substr($subString,$j,$l);
$pos = index($baseString,$str);
$num++ if ($pos<0);
}
}
acknowledgment $num;
}
The abstraction is to get two strings of the aforementioned breadth ramdonly, yield all accessible substrings
out of the first one, and try to bout them in the additional one with index().
Running this program with ActivPerl v5.6.1 on Windows 2000 arrangement gave me:
>SubstringTest.pl 50 1000
Number of tests = 1000
Number of characters = 50
Number of matches = 1257
Total time = 8 seconds
Average time = 0.008 seconds
>SubstringTest.pl 100 1000
Number of tests = 1000
Number of characters = 100
Number of matches = 4976
Total time = 31 seconds
Average time = 0.031 seconds
>SubstringTest.pl 200 1000
Number of tests = 1000
Number of characters = 200
Number of matches = 19916
Total time = 137 seconds
Average time = 0.137 seconds
|
numchar, local, 1000number, substringtest, performance, print, program, numtest, characters, tests, matches, index, seconds, secondsaverage, setstring, substr, substring, string, totaltime, , secondsaverage time, tests 1000number, print number, & setstring numchar, |
Also see ...
Java Analysis Program SubstringTest.javaTo analyze the achievement with Java language, I wrote the followingprogram, SubstringTest.java, in 1997 with about identical statement
This affiliate describes:What are typeglobs and how to use them to ascertain identifier aliases.How to admission variables from additional bales as aliases.How to use
Couple of absorbing notes:The first access in the attribute table defines an abandoned cord key. What s for?Identifier alias appointment statements assume to be processes during the
This affiliate describes:What is Accepted Aperture Interface (CGI).CGI ambiance variables provided by IIS.Query string.CGI appliance example, C
CGI Concern StringQuery String: The actual allotment of the requesting URL cord immediately afterwards the "?". Concern strings are usually acclimated to canyon a listo
This affiliate describes:How to configure IIS 5.0 to run Perl programs.How to use perlis.dll instead of perl.exe with IIS.Performance allegory apartof Perl, JSP, and
perl.exe vs. perlis.dllInstead of using perl.exe, you could aswell use perlis.dll to run your Perl programsthrough IIS. perlis.dll is the DLL of Perl for ISAPI.The advantage of using
Installing NMake 1.5Based on the documation, the accession action of RPC::XML bore requires the "make" utility. Since I am using a Windows arrangement now, so I charge to download a "make" account for Wi
RpcXmlServer2.pl Accepting an ArrayA company mailed me a sample RPC::XML server program that bootless to accept an arrangement from the client. The couldcause of the problem was accompanying to how an
This affiliate describes:Quick addition to SOAP. Overview of SOAP::Lite modules. Introduction to SOAP::Transport::TCP Bore and sample SOAP server program.