Narrow screen resolution Wide screen resolution Auto adjust screen size Increase font size Decrease font size Default font size default color grey color red color blue color

Linux Indore - Linux Users Group

Welcome, Guest
Please Login or Register.    Lost Password?
Go to bottomPage: 1
TOPIC: time.h header file in gcc
#534
time.h header file in gcc 2 Years, 1 Month ago Karma: 0
hi to all members

i've return a small c code which is a while loop,what i wanted is to calculate for how much amount of time this code is executiing so for that i used <time.h> header file and called "clock()" function from it but the problem that i m facing is clock functn is always returning 0(zero) instead of the time taken by the loop to execute.my loop is running for too big time too which = 0-99999999 which is much bigger time then CLOCKS_PER_SEC default value = 10000 as far as i know
can some 1 reply soon plzzzzzzz



thanks and Regards

Kapil
kapil (User)
null
Junior Boarder
Posts: 22
graphgraph
User Offline Click here to see the profile of this user
null null null null null null Location: null
The administrator has disabled public write access.
null
 
#537
Re:time.h header file in gcc 2 Years, 1 Month ago Karma: 0
Dear Kapil,
First of all this is not the right place to ask this question it belongs to programming section & you have posted it in Linux Newbie Lounge. You are using function in improper way, you should refer this

http://www.cplusplus.com/reference/clibrary/ctime/clock/
parasthetux (Moderator)
I am just a growing TUX
Moderator
Posts: 59
graphgraph
User Offline Click here to see the profile of this user
Gender: Male parasthetux@gmail.com parasuprime@yahoo.com Location: SGSITS indore Birthday: 01/01
Last Edit: 2009/12/23 16:08 By chetan.
The administrator has disabled public write access.
Parasthetux
 
#538
Re:time.h header file in gcc 2 Years, 1 Month ago Karma: 0
hello,
i m sorry i forgot the thing that to which section the query belong will keep in mind from now on.


thanks and Regards

Kapil
kapil (User)
null
Junior Boarder
Posts: 22
graphgraph
User Offline Click here to see the profile of this user
null null null null null null Location: null
The administrator has disabled public write access.
null
 
#539
Re:time.h header file in gcc 2 Years, 1 Month ago Karma: 5
I have moved post to correct category.
chetan (Admin)
Moderator
Posts: 93
graph
User Offline Click here to see the profile of this user
Gender: Male tuxchetan tuxchetan tuxchetan@gmail.com tuxchetan tuxchetan Location: Indore Birthday: 01/01
The administrator has disabled public write access.
./chetan
 
#540
Re:time.h header file in gcc 2 Years, 1 Month ago Karma: 0
You can use code like this.........

#include<stdio.h>
#include<sys/times.h>
#include<bits/time.h>

int main()
{
clock_t t;
unsigned long int i=0;
for(i=0;i<9999999;i++)
;
printf("Elapsed time: %u mili secs.n", (clock()*1000)/CLOCKS_PER_SEC);
return 0;
}
parasthetux (Moderator)
I am just a growing TUX
Moderator
Posts: 59
graphgraph
User Offline Click here to see the profile of this user
Gender: Male parasthetux@gmail.com parasuprime@yahoo.com Location: SGSITS indore Birthday: 01/01
The administrator has disabled public write access.
Parasthetux
 
#541
Re:time.h header file in gcc 2 Years, 1 Month ago Karma: 0
hello members,

well i did use some what the same code that paras has suggested but my o/p is always coming ZERO.

>>#include<stdio.h>
>>#include<sys/times.h>
>>#include<bits/time.h>

>>int main() {
>>clock_t t;
>>unsigned long int i=0;
>>for(i=0;i<9999999;i++);
>>printf("Elapsed time: %u mili secs.n", (clock()*1000)/CLOCKS_PER_SEC);
>>return 0;


and this is what i've done

#include <sys/types.h>
#include <unistd.h>
#include<stdio.h>
#include<times.h>
#include<time.h>

int main() {
long sec ; double d;
// clock_t is the type of value returned by clock() function i.e. No of clock ticks
clock_t begin ,end ;

begin = clock(); // Start the clock for calculating data Tx rate
for(i=0;i<9999999;i++);
end = clock(); // Stop the clock for calculating data Tx rate

printf("Begin %f and End %f and CLK_Sec is %d",begin,end,sec);
// this printf statement giving me ZERO for both variables

d = ((end - begin)/CLOCKS_PER_SEC);
// CLOCKS_PER_SEC shows the relation between clocks tics and a sec.

printf("That took %f seconds.n",d );
// this printf statement also giving me ZERO

return 0;
}

******** this is the same programme that i've tried after reading from
$info CLOCKS_PER_SEC



thanks and Regards
Kapil
kapil (User)
null
Junior Boarder
Posts: 22
graphgraph
User Offline Click here to see the profile of this user
null null null null null null Location: null
The administrator has disabled public write access.
null
 
Go to topPage: 1