473,387 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problem with "time.h" library

Hello everybody i want to execute a code which gives the duration of a running program by using the library "time.h" particularly the clock() function.
The problem is that i am not getting the right result and the program looks like:

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

int main(void)
{
float end;
clock_t start=clock();
.
.
.
.
end = (clock()-start)/CLOCKS_PER_SEC;
printf("%f",end);
return 0;
}

I have got 0.000000 as Output.
Thanks in advance for help.
Dec 10 '10 #1

✓ answered by donbock

All of the terms in the expression are integers so integer math is used, and then the integer result is cast to a float. Suppose your program takes less than a second to run -- then the result is zero.

4 2667
donbock
2,426 Expert 2GB
What do you expect the expression (clock()-start)%CLOCKS_PER_SEC to mean?
And why are you using modulo division?

You don't protect yourself from the possibility that this feature is not available. That is, you don't check if clock returned (clock_t)-1.
Dec 10 '10 #2
It is supposed to be (clock()-start)/CLOCKS_PER_SEC instead of (clock()-start)%CLOCKS_PER_SEC, it has been a mistake and excuse me.
So what i want by using that expression is to get the elapsed time between the beginning of the program and the end in second.
Dec 10 '10 #3
donbock
2,426 Expert 2GB
All of the terms in the expression are integers so integer math is used, and then the integer result is cast to a float. Suppose your program takes less than a second to run -- then the result is zero.
Dec 10 '10 #4
Thank you ,it works perfectly.
Dec 11 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Rahmi Acar | last post by:
Can any one redirect me to the place where i can find the stuff i need? Im by the way adding net time protocol so it will syncronise by it's own intergated watch. This is a start stopp application...
87
by: ziliath | last post by:
I recently tried out the Google "top coder" contest, as a C++ coder. I noticed immediately that they expected me to know STL. To which I say, what the fuck?! I may be missing something, but at...
11
by: RWC | last post by:
Hello, I'm having trouble converting code in Access XP / 2002. I have some code that declares an variable "as database" in Access 97, which is not recognized in Access XP. I've tried to find a...
6
by: gizmo | last post by:
I have a requirement to initiate more than one instance of an application using the filenames. (the example below will start two instances of MS Word). My problem is that I need to kill each...
5
by: Peter Steele | last post by:
We have an application that when it runs in the IDE in debug mode an unhandled exception is occurring in a system header file associated with STL stirngs. The actual statement that crashes is ...
4
by: Benjamin Joldersma | last post by:
Hello all, My company is installing a Bluecoat caching machine to help serve some of our dynamic content. This is fine for free documents, but we have to make a minor architectural tweak for...
1
by: Michael Barrido | last post by:
please help. I want to be able to change my computer's system "Time Zone" via vb.net code. is it possible? -mike
12
by: Zero | last post by:
Hi everybody, i want to write a small program, which shows me the biggest and smallest number in dependance of the data type. For int the command could be: ...
2
by: Usama Zulfiqar | last post by:
Hello guyz, One of my colleagues has made an upload website. We upload big data over the server via asp. Whenever I wanted to upload 5Mb file or more i receive ASP 0113 error. Is there any way...
23
by: deathtospam | last post by:
A day or two ago, I wrote a quick ASPX page with a CS codebehind using Visual Studio .NET 2005 -- it worked, I saved it and closed the project. Today, I came back to the project, reopened the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.