ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
A simple perl script will test this for you and tell you the answer. The test script basically loops x number of times, and varies the match so that it only hits every so often, using both 'eq' and a regexp:
Code:
#!/usr/bin/perl
#MAIN
{
my($loopcount) = 10000000;
my($matchevery) = 50000;
my($checkphrase) = "The quick brown fox jumps over the lazy dog.";
my($starttime, $endtime, $lookfor, $matchcount);
print "Looping $loopcount times, match every $matchevery...\n";
# eq test
#
$matchcount = 0;
$starttime = time;
print "eq: Started at ", localtime($starttime), "\n";
for(0..$loopcount) {
$lookfor = ($_ % $matchevery == 0) ? $checkphrase : "Something different";
$checkphrase eq $lookfor and $matchcount++;
}
$endtime = time;
print "eq: Ended at ", localtime($endtime), " with $matchcount matches\n";
print "eq: Time difference in seconds: ", ($endtime - $starttime), "\n";
# regexp test
#
$matchcount = 0;
$starttime = time;
print "regexp: Started at ", localtime($starttime), "\n";
for(0..$loopcount) {
$lookfor = ($_ % $matchevery == 0) ? "quick brown fox" : "Something different";
$checkphrase =~ /^.*${lookfor}.*$/ and $matchcount++;
}
$endtime = time;
print "regexp: Ended at ", localtime($endtime), " with $matchcount matches\n";
print "regexp: Time difference in seconds: ", ($endtime - $starttime), "\n";
exit;
}
and when run:
Code:
~/perl> ./eq_or_regexp.pl
Looping 10000000 times, match every 50000...
eq: Started at 1051123021053880
eq: Ended at 2851123021053880 with 201 matches
eq: Time difference in seconds: 18
regexp: Started at 2851123021053880
regexp: Ended at 452123021053880 with 201 matches
regexp: Time difference in seconds: 36
Last edited by TheLinuxDuck; 03-30-2005 at 11:53 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.