473,890 Members | 1,429 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GCC time.h problem.

Hello!
I am new to GCC.I've abt 4-5 yrs of experience in windows
'C' programming.I find GCC much slower than turbo or microsoft
compilers.Anywa y I wrote this small piece of code to calculate process
time .The code works fine in windows compilers but gives erratic output
in GCC.What could be the problem?

code-->
....
#include <time.h>
.....
void main() {

clock_t start, end;

start = clock();
//process();

end = clock();
printf("The time was: %f\n", (end - start) / CLK_TCK);
}
Is there any other way of doing the same?

Mar 3 '06
25 17105
Jaideep wrote:
I think you're placing too much trust in clock(). The number of ticks
per second (CLOCKS_PER_SEC , not CLK_TCK, is defined in the Standard)
is implementation defined and may not be good enough for your
purposes. I suggest you try execution profilers instead (e.g. gprof).

--
BR, Vladimir


I remember using execution profiler in keil cross compiler.Can I
implement it in a standalone program?I want to create a benchmarking
module.I've used clock() function several times with borland
compilers.Also execution profiler assumes full processor usage and
doesn't consider other processes running in background(Whic h are
irrelavant to C program).


Do not snip attribution lines. Do not quote signatures.

What you ask above is off-topic, quite unclear in what you actually want
to achieve, and so on. Come back when you have a genuine C question,
and learn how to post.

--
BR, Vladimir

I consider a new device or technology to have been
culturally accepted when it has been used to commit a murder.
-- M. Gallaher

Mar 4 '06 #21
Jordan Abel wrote:


Data point: CLOCKS_PER_SEC is one million on SUSv2 compliant unix
systems, but this is one point where some BSD systems don't conform to
that standard. For example, on FreeBSD, it is 128, and on OpenBSD, and
from what I can tell earlier versions of NetBSD, it is 100.

This implies nothing about the resolution of the clock, but on modern
systems it's more likely to be better than worse.

clock() resolution of 10 ms, as it apparently was on your NetBSD system,
remains a common value. This is still not relevant to the O/P, as he
refused to correct his code, which is likely to truncate his result to
whole seconds, then fail to display any reasonable approximation to that
value. Among the systems I have access to, the best clock() resolution
is 1/1024 second, but all of them have CLOCKS_PER_SEC set to 1 million.
Mar 5 '06 #22
On Sun, 05 Mar 2006 03:50:30 +0000, Tim Prince wrote:
Among the systems I have access to, the best clock() resolution is
1/1024 second, but all of them have CLOCKS_PER_SEC set to 1 million.


POSIX requires it to be 1 million (I can't imagine why) and since this
does not interfere with the C standard, implementations can kill two
standard birds with one #define.

--
Ben.
Mar 5 '06 #23
Ben Bacarisse <be********@bsb .me.uk> writes:
On Sun, 05 Mar 2006 03:50:30 +0000, Tim Prince wrote:
Among the systems I have access to, the best clock() resolution is
1/1024 second, but all of them have CLOCKS_PER_SEC set to 1 million.


POSIX requires it to be 1 million (I can't imagine why) and since this
does not interfere with the C standard, implementations can kill two
standard birds with one #define.


You are the second person (I think) to have said this. AFAICT, it's
not strictly true. POSIX doesn't require this; the X/Open System
Interface Extension does. This according to my copy of SUSv3.
Mar 6 '06 #24
On Mon, 06 Mar 2006 20:20:32 +0000, Micah Cowan wrote:
Ben Bacarisse <be********@bsb .me.uk> writes:
On Sun, 05 Mar 2006 03:50:30 +0000, Tim Prince wrote:
> Among the systems I have access to, the best clock() resolution is
> 1/1024 second, but all of them have CLOCKS_PER_SEC set to 1 million.


POSIX requires it to be 1 million (I can't imagine why) and since this
does not interfere with the C standard, implementations can kill two
standard birds with one #define.


You are the second person (I think) to have said this. AFAICT, it's not
strictly true. POSIX doesn't require this; the X/Open System Interface
Extension does. This according to my copy of SUSv3.


Ah. Yes, you are entirely correct. I have no idea what the X/Open System
Interface is but the POSIX (IEEE 1003.1) documents explain differences
between POSIX and XSI and, as you say, this is one of them. Thanks.

--
Ben.
Mar 6 '06 #25
On 2006-03-06, Ben Bacarisse <be********@bsb .me.uk> wrote:
On Mon, 06 Mar 2006 20:20:32 +0000, Micah Cowan wrote:
Ben Bacarisse <be********@bsb .me.uk> writes:
On Sun, 05 Mar 2006 03:50:30 +0000, Tim Prince wrote:

> Among the systems I have access to, the best clock() resolution is
> 1/1024 second, but all of them have CLOCKS_PER_SEC set to 1 million.

POSIX requires it to be 1 million (I can't imagine why) and since this
does not interfere with the C standard, implementations can kill two
standard birds with one #define.


You are the second person (I think) to have said this. AFAICT, it's not
strictly true. POSIX doesn't require this; the X/Open System Interface
Extension does. This according to my copy of SUSv3.


Ah. Yes, you are entirely correct. I have no idea what the X/Open System
Interface is but the POSIX (IEEE 1003.1) documents explain differences
between POSIX and XSI and, as you say, this is one of them. Thanks.


Broadly, it's what makes an implementation "unix" instead of just
another half-assed posix system.
Mar 6 '06 #26

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
12967
by: David Graham | last post by:
Hi I have asked this question in alt.php as the time() function as used in setcookie belongs to php - or does it belong equally in the javascript camp - bit confused about that. Anyway, can anyone here put me straight on the following: I had a look at the time() function came across this: "To clarify, it seems this function returns the time of the computer's clock and does not do any timezone adjustments to return GMT, so you are...
10
4798
by: Bart Goeman | last post by:
Hi, I have a question about how to put redundant information in data structures, initialized at compile time. This is often necessary for performance reasons and can't be done at run time (data structures are read only) Ideally one should be able to put the redundant information there automatically so no mistakes are possible, but in a lot of case I see no way how to do it.
38
2583
by: vashwath | last post by:
Might be off topic but I don't know where to post this question.Hope some body clears my doubt. The coding standard of the project which I am working on say's not to use malloc.When I asked my lead(I have just started working) he said we should not use dynamic allocation in real time systems, the code will not run in predictable time period.Can anybody tell what does he mean?Why the execution time becomes unpredictable? Thanks
3
1487
by: Servé Lau | last post by:
I encountered a situation today where time(NULL) returned -1. This was because at the point of the call the function could not read from the bus because it was locked by another process. I got the advice to use while((t = time(NULL)) == -1) { ; } I always thought that time only returned -1 when their was no timer functionality in the hardware and that it should return a valid value for all other cases. Is that correct? Should the loop...
9
7296
by: HL | last post by:
I am using VS 2005 Beta - C# Problem: The Timer fires a few milliseconds before the actual Due-Time Let's say a timer is created in the following manner: System.Threading.Timer m_timer = null; Let's declare a constant Int32 m_TimePeriod = 10000;
7
3029
by: Shimon Sim | last post by:
I have a custom composite control I have following property
80
3512
by: Charles Law | last post by:
Hi guys I have a time critical process, running on a worker thread. By "time critical", I mean that certain parts of the process must be completed in a specific time frame. The time when the process starts is not especially important, but it must be complete within a small number of seconds. The operations I am performing do not take a long time (hundreds of milliseconds), but as each part of the process is complete, my worker thread...
3
2749
by: Satish Itty | last post by:
Hi all, I have a big problem in my hands and not sure how I can fix this. Any suggestions would be greatly appreciated. I have a .NET 3 tier app developed in VS2003 and .NET 1.1. the client is a windows application and middle tier runs on IIS. Data is passed between the client and middle tier as DataSets and custom value object classes. The problem in my hand is that the client application is deployed in different time zones and the...
5
4060
by: Omer | last post by:
hi Everyone, I am using ASP.Net 2.0. When user logins, I check the credential and then made the cookie. My hoster's server is in Arizona region and I am in Pakistan. I set cookie's expiration time as 4 hours. It works perfectly fine on my PC and many other PCs which have correct time. But, if I set date to some old date, user is simply unable to login. This makes sense as probably cookie timing is not matching. Dilemma is that many users...
4
2479
by: Ken Fine | last post by:
I've been living with a frustrating issue with VS.NET for some months now and I need to figure out what the problem is. Hopefully someone has run into the same issue and can suggest a fix. I suspect some permissions problem. I'm running VS.NET 2008 in Vista. Symptoms and observations: * ASP.NET's native ImageMap and Image controls work just fine and provide a design-time preview of images that are referenced via the ImageUrl property *...
0
9979
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9826
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10925
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8018
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5854
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6058
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4682
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4276
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.