473,387 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to improve perf. ?

Hi,

I made a script which analyse very long strings and I need to make it
work differently depending of the 5 first chars of it.

I already do :

switch (true){
case ( ereg("12345", $data) ):
print '$data est un chaine 12345';
break;
case ( ereg("54321", $data) ):
print '$data est un chaine 54321';
break;
default:
print 'invalid data';
}

cause those first chars order doesn't matter, it can't be found in the
same order again ...

I know that there are lots of way to do this with php but could you tell
me which would the fastest way (talking about performance) to do it ?
(in order to make php not to analyse the entire string but only those 5
first chars ....)

thanks a lot,
erick

Jul 17 '05 #1
2 1725

On 16-Jan-2004, erickrefener <er***@spamitoudina.com> wrote:
I made a script which analyse very long strings and I need to make it
work differently depending of the 5 first chars of it.

I already do :

switch (true){
case ( ereg("12345", $data) ):
print '$data est un chaine 12345';
break;
case ( ereg("54321", $data) ):
print '$data est un chaine 54321';
break;
default:
print 'invalid data';
}

cause those first chars order doesn't matter, it can't be found in the
same order again ...

I know that there are lots of way to do this with php but could you tell
me which would the fastest way (talking about performance) to do it ?
(in order to make php not to analyse the entire string but only those 5
first chars ....)

thanks a lot,


Please cross-post in the future.

switch (substr($data,0,5))
{
case '12345':
...
case '54321':
...
}

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #2
First of all, what is the point of writing an if-else-if statement as a
switch statement?

As noted in the PHP manual preg_match() is faster than ereg. The problem
with you regular expression is you're telling it to search to whole text.
Put a ^ at the beginning to specify match at the beginning of the string.

if(preg_match("/^12345/", $data)) {
print '$data est un chaine 12345';
}
else if(preg_match("/^54321/", $data)) {
print '$data est un chaine 54321';
}
else {
}

Of course, the assumption here is that the actual regular expressions are
more complicated that a straight string comparison.

Uzytkownik "erickrefener" <er***@spamitoudina.com> napisal w wiadomosci
news:QL*******************@news20.bellglobal.com.. .
Hi,

I made a script which analyse very long strings and I need to make it
work differently depending of the 5 first chars of it.

I already do :

switch (true){
case ( ereg("12345", $data) ):
print '$data est un chaine 12345';
break;
case ( ereg("54321", $data) ):
print '$data est un chaine 54321';
break;
default:
print 'invalid data';
}

cause those first chars order doesn't matter, it can't be found in the
same order again ...

I know that there are lots of way to do this with php but could you tell
me which would the fastest way (talking about performance) to do it ?
(in order to make php not to analyse the entire string but only those 5
first chars ....)

thanks a lot,
erick

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Raj | last post by:
Hello all: We have a table with about 2400 cells. Our requirement is to highlight the cells in the table whose data has changed, every 5 seconds. Our script behaves relatively ok in Firefox, but...
9
by: Peng Jian | last post by:
I have a function that is called very very often. Can I improve its efficiency by declaring its local variables to be static?
3
by: Joshua Coady | last post by:
Do Trace calls have any impact on performance if Trace is disabled in the config file? Josh
11
by: Pohihihi | last post by:
I was wondering what is the ill effect of using try catch in the code, both nested and simple big one. e.g. try { \\ whole app code goes here } catch (Exception ee) {}
2
by: Stefan Kuhr | last post by:
Hello everyone, I hope this is not an FAQ and that somebody can answer this: As part of our webservice installation we run aspnet_regiis.exe -ir -enable on computers where the web...
11
by: Peted | last post by:
Im using c# 2005 express edition Ive pretty much finished an winforms application and i need to significantly improve the visual appeal of the interface. Im totaly stuck on this and cant seem...
0
by: joecch | last post by:
I have created a Message-Driven Bean application to receive message from a MQ. In fact, I anitcipate the application will receive around 10,000 messages a day and it has to do some operations like...
2
by: sdanda | last post by:
Hi , Do you have any idea how to improve my java class performance while selecting and inserting data into DB using JDBC Connectivity ......... This has to work for more than 8,00,000...
1
by: Ben | last post by:
Hi, I registered some custom perf counters that i want to use in my app (all of type NumberOfItems32). I added them under the same category name but different counter names... Same code work...
1
by: Ben | last post by:
hi, i have this line in a web app to create a custom perf category: PerformanceCounterCategory.Create(categoryName, categoryDesc, PerformanceCounterCategoryType.SingleInstance, ccdc); ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.