how to speed up the code? 
Author Message
 how to speed up the code?

Hi,
  Anyone can help me to optimise the following code especially the
speed?
I would like to do a counting.
say, given abbacb
I count
abb, bba, bac, acb
and according to their counts, output a character follows the 3
character group.  That is:
abb  a
acb  ?
bac  b    
bba  c
The output is a?bc ? can be anything.

I perform this by using the integer values of the 3 character group.
but it is very slow.  Hope that somebody can help.
E-mail me is prefered.
Thanks in advance

/**********************code start here ****************/  

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#define MAX 50000

main()
{
  unsigned int i,j,len,num;
  FILE *filein;
  char in[15],inbuffer[MAX],*post;
  unsigned int counter[MAX]={0},outbuffer[MAX]={0},sum=0;
  printf("Enter an input file\n");
  scanf("%s",in);
  filein=fopen(in,"rb");
   setmode(fileno(filein),O_BINARY);
   post=&inbuffer;
   for(;;){
    len=fread((char *)inbuffer,1,(size_t)MAX,filein);
    if(len==0) break;
         for(i=0; i<len-2; i++)
          {
            num=0;
              for(j=0;j<3; j++) {
                 num=num*10+(*(post+i+j));
         }
         counter[num]++;
      }
      for(i=0; i<MAX; i++){
        if(counter[i]>0){
            for(j=0;j<len; j++){
        sum=inbuffer[j]*100+inbuffer[j+1]*10+inbuffer[j+2];
              if(i==sum){
        outbuffer[0]=inbuffer[j+3];
                     }//end if
                    }
                     }//end if
                        }
    } //end for

Quote:
}

/**************** code end ***************/
--



Fri, 23 Nov 2001 03:00:00 GMT  
 how to speed up the code?
At Mon, 07 Jun 1999 03:43:09 GMT alex

Quote:

> Hi,
>   Anyone can help me to optimise the following code especially the
> speed?

Een testje om te zien wat Cnews met een Approved berichtje doet.

--
Richard

Your treasure house is within; it contains all you'll ever need.
                                                Hui-Hai



Fri, 23 Nov 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Bad Address from Speed Optimized Code

2. Speed difference in Managed and Unmanaged code

3. Problem with Visual Studio .NET (C++) - Maximise Speed (/O2) - Unmanaged Code

4. Optimization for Maximum speed generates wrong code

5. Need code to compare speed of two computers.

6. c/c++ Code speed after threading ??

7. How to optimize execution speed of code ??

8. Use of static to speed up code?

9. Tool for measuring speed of C code wanted

10. Help! A beginner out in speeding up code

11. The speed of the code

12. Speed of generated code

 

 
Powered by phpBB® Forum Software