Hi everyone,
I am struggling with the following problem. I would like to measure the
wall clock time required to run a section of the code with a precision
of milliseconds. The attached code does the job on Windows Xp. However,
the code is not portable, as it fails to compile on Linux Red Hat. This
is the command and the errors:
# gcc -c time_loop.c
time_loop.c: In function 'main':
time_loop.c:34: error: storage size of 'tstruct1' isn't known
time_loop.c:34: error: storage size of 'tstruct2' isn't known
time_loop.c:26: warning: return type of 'main' is not 'int'
I will be grateful if anyone could tell know how to fix this problem so
that I can use the same code both on WinXp and Linux. In case it is not
possible, it will be very helpful to have alternative, preferably
concise, code that works on Linux.
Thanks in advance,
Pedro
Ps: and this is time_loop.c
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/timeb.h>
/* GLOBAL PARAMETERS DECLARATION */
#define NM 25000000
/* MAIN ROUTINE */
void main(void)
{
int i;
long idb; /* with "register", it seems to take longer! */
/* register long idb; */
double tms1, tms2, telapsed;
float diff[12];
float vec_a[12]={6., 3., 4., 3., 7., 2., 1., 3., 8., 4., 9., 3.};
float vec_b[12]={3., 7., 2., 1., 3., 8., 4., 9., 6., 3., 4., 3.};
struct __timeb64 tstruct1, tstruct2;
/* Starting time */
_ftime64( &tstruct1 );
tms1=(double)ts truct1.time+((d ouble)tstruct1. millitm/1000.0);
for(idb=0; idb < NM; idb++)
{
for(i=0; i < 12; i++) diff[i]=vec_a[i]-vec_a[i];
}
/* Finishing time */
_ftime64( &tstruct2 );
tms2=(double)ts truct2.time+((d ouble)tstruct2. millitm/1000.0);
telapsed=tms2-tms1;
printf("It took:\t%lf seconds to calculate diff %d times\n",
telapsed, NM );
} 5 4945 pe************* @gmail.com wrote:
Hi everyone,
I am struggling with the following problem. I would like to measure the
wall clock time required to run a section of the code with a precision
of milliseconds. The attached code does the job on Windows Xp. However,
the code is not portable, as it fails to compile on Linux Red Hat. This
is the command and the errors:
# gcc -c time_loop.c
time_loop.c: In function 'main':
time_loop.c:34: error: storage size of 'tstruct1' isn't known
time_loop.c:34: error: storage size of 'tstruct2' isn't known
time_loop.c:26: warning: return type of 'main' is not 'int'
I will be grateful if anyone could tell know how to fix this problem so
that I can use the same code both on WinXp and Linux. In case it is not
possible, it will be very helpful to have alternative, preferably
concise, code that works on Linux.
Standard C does not offer a way to measure milliseconds
therefore I don't think there is a way to have such code
which works both on Linux and Windows. For Linux specific
advice you should ask at comp.os.linux.d evelopment.apps
But there is a way to fix the following warning on both systems
time_loop.c:26: warning: return type of 'main' is not 'int'
I'll leave it as an exercise to find how. pe************* @gmail.com wrote:
time_loop.c:26: warning: return type of 'main' is not 'int'
If this is the warning your compiler gave you it's
either broken or the people who wrote it have a
very strange sense of humor. But I suspect that
you simply didn't copy the warning correctly. Cut
and paste is the only reliable method for programmes
and compiler messages.
"Spiros Bousbouras" <sp****@gmail.c omwrites:
>pe************* @gmail.com wrote:
time_loop.c:26: warning: return type of 'main' is not 'int'
If this is the warning your compiler gave you it's
either broken or the people who wrote it have a
very strange sense of humor. But I suspect that
you simply didn't copy the warning correctly. Cut
and paste is the only reliable method for programmes
and compiler messages.
What do you mean? The OP's program had:
void main(void)
{
...
}
The warning seems perfectly correct; he defined a function called
"main" whose return type is not int.
And yes, that's the exact warning message I get from gcc for
"void main(void)".
The line number doesn't match the code he posted, but that indicates a
copy-and-paste error for the code, not for the warning.
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Keith Thompson wrote:
"Spiros Bousbouras" <sp****@gmail.c omwrites:
pe************* @gmail.com wrote:
time_loop.c:26: warning: return type of 'main' is not 'int'
If this is the warning your compiler gave you it's
either broken or the people who wrote it have a
very strange sense of humor. But I suspect that
you simply didn't copy the warning correctly. Cut
and paste is the only reliable method for programmes
and compiler messages.
What do you mean?
My mind worked strangely. I understood
"return type of 'main' is not 'int'"
not as referring to main as appears in the
programme but as saying that the return
value of main should not be int.
The warning is indeed correct. pe************* @gmail.com writes:
Hi everyone,
I am struggling with the following problem. I would like to measure the
wall clock time required to run a section of the code with a precision
of milliseconds.
<snip>
I will be grateful if anyone could tell know how to fix this problem so
that I can use the same code both on WinXp and Linux. In case it is not
possible, it will be very helpful to have alternative, preferably
concise, code that works on Linux.
This can't be done in standard (and hence portable) C. In such cases
it is often best to go the Unix(ish) route and use a function
specified in the POSIX standard since there are POSIX C libraries for
a lot of systems (including MS ones).
<offtopic>The POSIX function you want is gettimeofday. More
information and code examples would probably follow if you post on
comp.unix.progr ammer.</offtopic>
--
Ben. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: James Harriman |
last post by:
Hi,
I need to be able to measure a time interval in milliseconds on a windows
machine. I have tried using time.clock() but it appears to measure time in
seconds...Is there a way to measure time more precisely?
Regards,
James Harriman
v38zy@unb.ca
|
by: Peter Hansen |
last post by:
I would like to determine the "actual" elapsed time of an operation
which could take place during a time change, in a platform-independent
manner (at least across Linux/Windows machines).
Using time.time() doesn't appear to be suitable, since time might jump
forwards or backwards at the user's whim, if the system clock is reset,
or when a daylight savings time change occurs.
Using time.clock() doesn't appear to be suitable on Linux,...
|
by: Ufit |
last post by:
I must precisely measure the time of calculation.
f.ex
clock_t begin,finish,time;
begin=clock();
Calculations();
finish=clock();
time=finish-begin;
but unfortunatelly finish is equal to begin
|
by: Randy Shore |
last post by:
I have developed an Access application that replaces the paper scoresheet
scoring for QuizBowl competitions with live, lap-top based scoring. Among
other tasks the application displays a score board that is visible to the
teams that also includes the countdown clock that times the eight-minute
halfs. I have simulated the countdown clock by using the OnTimer event for
the form with the timer set for 1000 milliseconds. The problem that I...
|
by: aegis |
last post by:
What is wall clock time? the standard doesn't define it
but I see its use in past posts on clc.
--
aegis
| |
by: Geert Jansen |
last post by:
Hi!
I'm trying to profile an application that I believe is blocking on I/O
for a significant amount of time. In trying to dig down where this
happens, I profiled the application with hotshot. The results are not
really usable however as it seems to display the amount of CPU time
which for my application is much lower than the total run time.
Is possible to use hotshot with wall clock time, i.e. is it possible to
have the code fragment...
|
by: Ron Adam |
last post by:
I'm having some cross platform issues with timing loops. It seems
time.time is better for some computers/platforms and time.clock others, but
it's not always clear which, so I came up with the following to try to
determine which.
import time
# Determine if time.time is better than time.clock
# The one with better resolution should be lower.
|
by: anto.anish |
last post by:
Hi -
I have been using clock() for calculating CPU time and time() for
calculating Wall time. However, since time() does not provided milli/
microsecond accurancy, i started using gettimeofday() as below to
calculate walltime,
struct timeval tv1,tv2;
struct timezone tz1, tz2;
gettimeofday(&tv1,&tz1);
|
by: dmjpro |
last post by:
<body onload="setDynColck()">
<input type='hidden' id='millsecs' value='Capturing the milliseconds from server side'/>
/*******
Some server side coding to manipulate the current time
**************/
<td align="center" id="hour1" class="searchbgcolor"><%=First Digit of Hour%></td><td align="center" id="hour2" class="searchbgcolor"><%=Second Digit of Hour%></td>
<td align="center" class="searchbgcolor">.</td>
|
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...
|
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,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |