A
ArShAm
Hi there
Please help me to optimize this code for speed
I added /O2 to compiler settings
I added /Oe to compiler settings for accepting register type request , but
it seems that is not allowed and if I remove register type for "l" , time of
generating codes doesn't change
the original code makes some files , but I removed that section to make it
simple for you to read
please help me to optimize it for faster running
my system is Windows XP , 512 Mb ram , 1.6 Intel
Regards
ArShAm
Code is here :
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
const int NUM=7;//number of characters in each word
const int total=20000000;//total generation
char q[total][NUM+1];// the table
void main(void)
{
int NUMBERS=26;//size of al array
char al[]="abcdefghijklmnopqrstuvwxyz"; //array to generate a random code
register int l;//my windows XP doesn't respect this request
for(int i=1;i<total;i++)
{
for(int j=0;j<NUM;j++)
{
q[j]=al[rand()%NUMBERS];//generating each password
}
for(l=0;l<i;l++)//comparing if it is unique or not
{
if(!strcmp(q,q[l]))
{
printf(" %d was equal to %d with %s:%s value\n",i,l,q,q[l]);
i--;
break;
}
}
if(i%10000==0)printf("%d\n",i/10000);//each 10,000 times shows that the
program is runing
//printf("%s\n",q);
}
printf("\r\nDONE");
getchar();
}
Please help me to optimize this code for speed
I added /O2 to compiler settings
I added /Oe to compiler settings for accepting register type request , but
it seems that is not allowed and if I remove register type for "l" , time of
generating codes doesn't change
the original code makes some files , but I removed that section to make it
simple for you to read
please help me to optimize it for faster running
my system is Windows XP , 512 Mb ram , 1.6 Intel
Regards
ArShAm
Code is here :
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
const int NUM=7;//number of characters in each word
const int total=20000000;//total generation
char q[total][NUM+1];// the table
void main(void)
{
int NUMBERS=26;//size of al array
char al[]="abcdefghijklmnopqrstuvwxyz"; //array to generate a random code
register int l;//my windows XP doesn't respect this request
for(int i=1;i<total;i++)
{
for(int j=0;j<NUM;j++)
{
q[j]=al[rand()%NUMBERS];//generating each password
}
for(l=0;l<i;l++)//comparing if it is unique or not
{
if(!strcmp(q,q[l]))
{
printf(" %d was equal to %d with %s:%s value\n",i,l,q,q[l]);
i--;
break;
}
}
if(i%10000==0)printf("%d\n",i/10000);//each 10,000 times shows that the
program is runing
//printf("%s\n",q);
}
printf("\r\nDONE");
getchar();
}