473,404 Members | 2,174 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,404 software developers and data experts.

How can i optimize the follow function?

15
Expand|Select|Wrap|Line Numbers
  1. char start=0;
  2.     char isfloat=0;
  3.     char tmp_num[10];
  4.     int i=0,j=0;
  5.     char *end;
  6.  
  7.     memset(tmp_num,0,10);
  8.  
  9.     end=(*str)+strlen(*str);
  10.  
  11.     while(((*str)++)<=end)
  12.     { 
  13.         if( isdigit(**str) )
  14.  
  15.         {
  16.             start=1;
  17.             tmp_num[j] = **str;
  18.             j=j+1;
  19.         }
  20.         if( ispunct(**str) && start==1)
  21.  
  22.         {
  23.             isfloat=1;
  24.             tmp_num[j] = **str;
  25.             j=j+1;
  26.         }
  27.  
  28.         if( (**str==' ') || (**str==0) )
  29.         {
  30.             if(isfloat==1 && start==1)
  31.             {
  32.                 *d=atof(tmp_num);
  33.                 return 0;
  34.             }
  35.             if(*(*str+1)==0)
  36.             {
  37.                 return 1;
  38.             }
  39.             start=0;
  40.             isfloat=0;
  41.             j=0;
  42.             memset(tmp_num,0,10);
  43.         }
  44.  
  45.     }    
  46.  
  47.     return 1;
  48. }

I have large data sets and this functios creates problems because of the isdigit and ispunct function. Do you have any idea to replace them??
Thnx guys!!
Nov 22 '07 #1
2 1308
Well, you can save a call to

memset(tmp_num,0,10);

using

tmp_num[0]=0;
and doing
tmp_num[j++] = **str;
tmp_num[j]=0;

I dont know whether that would help.

Anyway, try using some optimization flag in your compiler, like -O2 or -O3 and see if your program speed improves.
Nov 22 '07 #2
pilafi
15
I tried to use the optimization flags, but the speed doesnt change. I forgot to give you a detail that this function is a function for getting the next double you find in the file. It works normally, but i have some files with a lot of doubles, really lot and my program crasses in these files. Please help guys!!Thnx!!
Nov 23 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: André Nęss | last post by:
Photoshop has a function called optimize to file size which tries to fit an image to some given file size. Because I need to make sure no images on a site I'm working on are larger than X KB I need...
4
by: Ragnorack67 | last post by:
Hi, I am looking for a complete PHP function that will resize & optimize any JPG image with very good end results. My server is running PHP 4.3.8. So, for instance a 1600x1200 JPG at...
9
by: Julie | last post by:
Due to circumstances beyond my immediate control, I've been put in charge of getting some JavaScript code in place and operational ASAP. Normally, I'm a C++ programmer, and previously have only...
10
by: Chris Martin | last post by:
Background: Our main menu is built using a simple unordered list containing other ULs. There is a table on a page that holds the subnav. Because of certain circumstances, I need to build the subnav...
9
by: Rune | last post by:
Is it best to use double quotes and let PHP expand variables inside strings, or is it faster to do the string manipulation yourself manually? Which is quicker? 1) $insert = 'To Be';...
11
by: Michael B. | last post by:
I'm still learning C so I've written a simple app which lets you make a contact list (stored as a linked list of structs), write it to a file, and read it back. It works fine, but I notice in my...
0
by: Daniel | last post by:
Hi there, I recently came across an interesting option when right clicking on a project (Right click on the project -> properties -> Configuration Properties ->Build -> Optimize) There is an...
6
by: Silly | last post by:
byte Name = new byte; uint len = (uint)Name.Length; uint err = MyFunction(devID, out Name, out len); When this code is run in release build with optimize code set to true, len is evaluated to...
4
by: George2 | last post by:
Hello everyone, Why visual studio does not optimize constructor in this case? I do not understand what the MSDN mentioned, if use different named object, compiler can not optimize. Why? ...
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: 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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.