Hello dear all. i need a help where i'm try to calculate execution time for my program. seem i have a problem with how to set it up.

#include <iostream>
#include <time.h>
#include <sys/timeb.h> 
typedef int tRow[10];
int N, i;
int x[100], xi[100];      /* The permutation and its inverse */
int dir[100]; 
using namespace std;
int count = 1;

void rotate(int *x, int N)
{
     int temp, i;
     temp = x[1];
     for (i = 1; i < N ; i++)
           x[i] = x[i+1];
     x[N - 1] = temp;
}// end rotate()

void reverse(int *x, int N) {
   
    for (int i=1; i<N-1; i++) {
        int temp = x[i];
        x[i]     = x[N-i-1];
        x[N-i-1] = temp;
    }
    return;
}// end reverse


void print()
{
    int i;
   for (i=1; i <= N; ++i)
      cout << x[i] << "" ; 
}

void trans( int x, int y )
{
   printf("(%2d  %2d)", x , y);
   cout << endl;
} 
void move( int j, int d )
{
   int z;
   trans( xi[j], xi[j]+d );
   z = x[xi[j]+d];
   x[xi[j]] = z;
   x[xi[j]+d] = j;
   xi[z] = xi[j];
   xi[j] = xi[j]+d;
} 

void starterlist (int *x, int start )
{  
   int i, j,  fact=1;
   if (start > N )
      print();
   else
   {
      starterlist( x, start+1 );
      for (i=2; i<= start-1; ++i) // fix element 1,that's why start i=2.
      {
			move( start, dir[start] );
			starterlist(x, start+1 );
			 count++ ;     //counting the starter
      }
		dir[start] = -dir[start];
   } 
	
   for(j=1;j<=N;j++)
   	fact = fact*j;
   
	//cout<<endl;
	//cout<<"count = "<<cout<<endl;
	//cout<<"fact = "<<fact<<endl;
   // if (count == (fact/(2*N))) 
		//exit(0);
} 

int main ()
{  
	int y;
   cout << "Enter the number of elements: " ;
   cin>> N;
   cout<< endl;
int ftime(struct timeb *tp);

struct timeb time_before,timeafter;
long total_time_taken;

ftime(&time_before);

   for (i=1; i<=N; ++i)
   {
      dir[i] = -1; 
	   x[i] = i;
      xi[i] = i;
   }
	cout<<"Possible Starters are : " << endl;
   starterlist ( x, 1 );
   cout<< "\n";
   cout<<"count = "<<count<<endl; 
   y=count/2;
   cout<<"y = "<<y<<endl; 
   for (int i=1; i <= y; ++i)
      cout << x[i] << "" ; 
ftime(&time_after);
/*Calculate the time difference in milliseconds */
total_time_taken = (time_after.time  - time_before.time) * 1000 +(time_after.millitm- time_before.millitm);
}

i use this syntax as follows:

int ftime(struct timeb *tp);
struct timeb time_before,timeafter;
long total_time_taken;
ftime(&time_before);
ftime(&time_after);
/*Calculate the time difference in milliseconds */
total_time_taken = (time_after.time  - time_before.time) * 1000 +(time_after.millitm- time_before.millitm);
} // main()

1) delete line 87 because its unnecessary. The function is prototyped in the header file.

2) line 108: time_after is never declared (see spelling on line 89)

There's a really easy to use timer in VUL (part of VXL). It may be a bit of overhead to install it, but it works great once it's installed.

Dave

ok, its done. i just wondering the output is it in second or else
if i use

struct timeb time_before,time_after;
long total_time_taken;
ftime(&time_before);
ftime(&time_after);
total_time_taken = (time_after.time  - time_before.time);
cout << total_time_taken <<"";
This article has been dead for over six months. Start a new discussion instead.