I wrote this round robin code and I want to calculate Response Time and Throughput

#include <stdio.h>
#include <stdlib.h>

// Data Structures
typedef struct process{
	char 	jobName;
	int		arrivalTime;
	int 	execTime;
	struct process *next;
} P;

typedef struct result{
	char Name;
	struct result *next;
} result;
// End of Data Structures

int quantum;
int time=0;
int jobCounts=0;

// Function Prototypes
void add_to_process_list(P **List,P *data);
void add_to_result_list(result **List,char name);
P *readData(char* fileName);
void writeData(result *res,char *OUT);
P *removeFromList(P **head,P **El);
int jobCount(P *head);
// End of Function Prototypes

int main(int argc, char *argv[]){
	P *pList=NULL,*tmpNode=NULL;
	result *RR_result=NULL,*JR=NULL;
		
	pList=readData(argv[1]);
	jobCounts=jobCount(pList);
	
	if(pList!=NULL){
		tmpNode=pList;
			
		while(tmpNode!=NULL){
			if(tmpNode->arrivalTime<=time){
				JR=(result *)malloc(sizeof(result *));
				add_to_result_list(&RR_result,tmpNode->jobName);
				tmpNode->execTime-=quantum;
				if(tmpNode->execTime==0)
					tmpNode=removeFromList(&pList,&tmpNode);
				else
					tmpNode=tmpNode->next;	
				time+=quantum;	
			}else
				tmpNode=tmpNode->next;
		}
		
		writeData(RR_result,argv[2]);
		return 0;
	}else{
		return 1;
	}	
}

void add_to_process_list(P **List,P *data){
	P *new=malloc(sizeof(P));
	new->arrivalTime=data->arrivalTime;
	new->execTime=data->execTime;
	new->jobName=data->jobName;
	
	if(*List==NULL){
		new->next=new;
		*List=new;
	}else{
		P *tmp;
		tmp=*List;
		while(tmp->next!=(*List)) tmp=tmp->next;
		tmp->next=new;
		new->next=*List;
	}	
}

void add_to_result_list(result **List,char name){
	result *new=malloc(sizeof(result));
	new->Name=name;
	new->next=NULL;
	
	if(*List==NULL){
		*List=new;
	}else{
		result *tmp;
		tmp=*List;
		while(tmp->next!=NULL) tmp=tmp->next;
		tmp->next=new;
	}	
}

P *readData(char* fileName){
	P *head=NULL,*cur=NULL;
	char Name,*tmp;
	int AT,ET;
	FILE *iF;
	tmp=(char*)malloc(sizeof(char*));
	
	if((iF=fopen(fileName,"r"))>0){
		fgets(tmp,255,iF);
		sscanf(tmp,"%d\n",&quantum);
		
		while(!feof(iF) && 	fgets(tmp,255,iF)){
			sscanf(tmp,"%c %d %d\n",&Name,&AT,&ET);
			cur=(P *)malloc(sizeof(P *));
			cur->jobName=Name;
			cur->arrivalTime=AT;
			cur->execTime=ET;
			add_to_process_list(&head,cur);
		}
		
		fclose(iF);
		return head;
	}else{
		printf("Fatal error:\n\tError openning input file.\n");
		return NULL;		
	}
}

void writeData(result *res,char *OUT){
	result *tmp=res;
	FILE *oF;
	int tmpCounter=1;
	float throughput=(jobCounts/time);
	
	if((oF=fopen(OUT,"w"))>0){
		fprintf(oF,"%-15s %-15s\n","Job Name","Execution Time");
		while(tmp!=NULL){
			if(tmp->next!=NULL && tmp->Name==tmp->next->Name)
				tmpCounter++;
			else{
				fprintf(oF,"%-15c %-15d\n",tmp->Name,tmpCounter*quantum);
				tmpCounter=1;
			}
			tmp=tmp->next;
		}
		fprintf(oF,"Response Time: %d\n",0);
		fprintf(oF,"Throghput: %0.2f\n",throughput);		
		
		fclose(oF);
	}else{
		printf("Fatal error:\n\tError openning output file.\n");
	}
}


P *removeFromList(P **head,P **El){
	P *tmp=*head;
	if((*El)->next==*El){
		free(*El);
		return NULL;
	}else{
		while(tmp->next!=NULL && tmp->next!=*El) tmp=tmp->next;
		tmp->next=tmp->next->next;
		free(*El);
		return tmp->next;
	}
}

int jobCount(P *head){
	P *tmp=head;
	int count=1;
	if(tmp->next==tmp){
		return 1;
	}
		
	while(tmp->next!=head) {
		tmp=tmp->next;
		count++;
	}	
	return count;
}

How should I do that?

Thanks

Time is usually measured in C with two clock_t variables:

#include <time.h>
#include <stdio.h>
#include <dos.h>

int main(void)
{
   clock_t start, end;
   start = clock();

   delay(200);  //adjust as needed for your compiler and OS
   //sleep(200);  //ditto

   end = clock();
   printf("The time was: %f\n", (end - start) / CLK_TCK);

   return 0;
}

This is old Turbo C code. Change CLK_TCK to suit your own compiler macro (may be TICKS_PER_SEC, or ??)

Throughput is just units / time to process. What units would you suggest for your program?

hii..actually i m caluclating the throught put using matlab...can any one help for me....
i caluclating throughput for both roundrobin scheduling n quantized prportional fair scheduling
..
will any one help me..
its so imp for meee


is so plz mail ur reply to mahesh.g.4u@gmail.com

OK, but you say you're using matlab to measure this, not C.

Do you have a C question?

If not, I'd Google up the answer to your other questions. You MIGHT find an answer here, but it's a real gamble, imo.

Good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.