473,386 Members | 1,773 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,386 software developers and data experts.

time problems

hi,
if any body can tell me how to write a function that will create delay
according to the speed of processor

Nov 15 '05 #1
5 2040
"lucifer" <um**********@gmail.com> writes:
if any body can tell me how to write a function that will create delay
according to the speed of processor


This can't be done in standard C. See question 19.37 in the C FAQ,
and try a newsgroup specific to your system.

It's not clear what you mean by "delay according to the speed of
processor". Do you want to delay for a longer period of time on
slower processors? There's no need to answer here, but be sure to
make it clear when you post to a more appropriate newsgroup.

--
Keith Thompson (The_Other_Keith) 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.
Nov 15 '05 #2
actually i am transmitting data over wireless medium so i have to
control the data ie slow it down thats i have to get a delay in the
transmitting function inversely to the speed of the the processor the
code i have been using is
void delay(int n)
{
clock_t start = clock();
while( ( ( (clock()-start)/CLOCKS_PER_SEC )*1000 )<n) ;
}

the n is calculated frm another function

Nov 15 '05 #3
lucifer wrote:

Provide context otherwise we don't know why you are posting this. Only
yesterday and the day before that and the day before that (and probably
today as well) instructions were posted together with the reason why you
need to provide context.

I believe you can either hit the preview button before writing your
reply or instead of using the reply button beneath the message you the
options button above to reveal a reply button that works properly.

Most of us do *not* use Google because it is a horrible interface. There
is no guarantee we have received the message you are replying to or, if
we have, that we have not forgotten what it said and have no convenient
way to view it.
actually i am transmitting data over wireless medium so i have to
control the data ie slow it down thats i have to get a delay in the
transmitting function inversely to the speed of the the processor the
code i have been using is

void delay(int n)
{
clock_t start = clock();
while( ( ( (clock()-start)/CLOCKS_PER_SEC )*1000 )<n) ;
}

the n is calculated frm another function


Good for you. Of course, if clock_t is an integral type and
CLOCKS_PER_SEC is integral (which it will be if clock_t is) then it
might not do quite what you want because it will throw away the
remainder of the division.

Also clock() returns processor time, *not* wall clock time, and in many
environments depending on loading this can be vastly different.

You don't check whether your call to clock() succeeds, it returns
(clock_t)-1 if it fails.

There is no guarantee as to the precision or accuracy of clock().

<OT>
If this is on a multi-tasking system you are burning processing cycles.
</OT>

For a better solution ask in groups dedicated to your system (or systems
of interest) since there is no good portable solution.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 15 '05 #4
"Keith Thompson" <ks***@mib.org> wrote in message
news:ln************@nuthaus.mib.org...
"lucifer" <um**********@gmail.com> writes:
if any body can tell me how to write a function that will create delay according to the speed of processor


This can't be done in standard C. See question 19.37 in the C FAQ,
and try a newsgroup specific to your system.

It's not clear what you mean by "delay according to the speed of
processor".


Of course it is. Dig out an old video game. I like Dragon Strike because
you get to ride on the back of the Dragons. Blue Dragon are Electric;
Red dragons are fire. Very cool game - ran very slow on my 486 (I
think - maybe even 386).

Finding it in my garage, I loaded onto a 400MHz AMD Whatever (PIII or
more) machine and it was crap! The opposing dragons flew rings around
me! It was totally unplayable!!

The poster is asking how to time a game so that it works well on old
processors, but doesn't become unplayable under modren* technology. The
standard of timing via the video rate is probably out-dated...

One needs to consider how to delay a game based on how fast it is
expected to run. This is one of the reasons I prefer to write games that
are turn-based. <Palm game plug omitted>

* I used "modren" to describe modern stuff that will surely and
obviously be replaced with faster stuff. Your cell phone might well be
the most modren available...

--
Mabden
Nov 15 '05 #5
"Mabden" <mabden@sbc_global.net> writes:
"Keith Thompson" <ks***@mib.org> wrote in message
news:ln************@nuthaus.mib.org...
"lucifer" <um**********@gmail.com> writes:
> if any body can tell me how to write a function that will create
> delay according to the speed of processor


This can't be done in standard C. See question 19.37 in the C FAQ,
and try a newsgroup specific to your system.

It's not clear what you mean by "delay according to the speed of
processor".


Of course it is. Dig out an old video game. I like Dragon Strike because
you get to ride on the back of the Dragons. Blue Dragon are Electric;
Red dragons are fire. Very cool game - ran very slow on my 486 (I
think - maybe even 386).


I see what you mean. It just wasn't clear to me that that's what the
original poster meant. I would describe what you're talking about as
delaying for a particular real time interval *regardless* of the speed
of the processor. If you do it with a busy loop, you have to
calibrate the loop to the processor speed, but if you do it with a
system call that delays for a specified real time interval, the
processor speed is irrelevant (at least to the caller).

--
Keith Thompson (The_Other_Keith) 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.
Nov 15 '05 #6

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

Similar topics

11
by: Cameron Laird | last post by:
*The Chronicle of Higher Education*, which is more-or-less authoritative for US university administrations, is spon- soring a discussion on the place of open-source in universities ("... are such...
0
by: Eric S. Johansson | last post by:
more questions about performance measurements in python. I solve the problems I had with shelf by not using it. I'm doing a direct pickle to and from file of an entire dictionary. That knocked off...
6
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...
3
by: Benny | last post by:
Hi All, In an application I write, I need to have some mapping service, where I can select two locations, which shall calculate the distance and mainly the time(could be approximate) to travel...
17
by: Eric Lindsay | last post by:
Is learning to write CSS a better use of time than finding and using a package that produces complete web pages? I've moved to a new platform (Macintosh), taking with me about 400 personal web...
43
by: Mike MacSween | last post by:
Or something to do with Nulls in PK. Which is obviously wrong. OK, after a diversion of having to earn money its back to the free one. The orchestral management system. At the E-R level: An...
4
by: HNguyen | last post by:
Hi, I have a Web application in ASP.NET. My Application allows the users upload files into the server after checking their user names and passwords. For each transaction, the Web program will...
6
by: dredge | last post by:
Hi, the server that hosts my PHP pages has its clock set to Greenwich Mean Time (GMT timezone 0). I need for my PHP scripts to have access to my local time which is Central Standard Time in the...
5
by: Charles May | last post by:
Anyone have a simple concept for the best way to store timeclock information in a database. I currently have my table set up like this with a typical daily entry. tcID empID Type ...
27
by: CodeMonk3y | last post by:
gotta question on sizeof keyword does the sizeof keyword calcuates the size at compile time or run time ?? -- Posted on news://freenews.netfront.net - Complaints to news@netfront.net --
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: 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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
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,...
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.