473,806 Members | 2,346 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2089
"lucifer" <um**********@g mail.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_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.
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.or g> wrote in message
news:ln******** ****@nuthaus.mi b.org...
"lucifer" <um**********@g mail.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_glo bal.net> writes:
"Keith Thompson" <ks***@mib.or g> wrote in message
news:ln******** ****@nuthaus.mi b.org...
"lucifer" <um**********@g mail.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_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.
Nov 15 '05 #6

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

Similar topics

11
2143
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 choices too risky for colleges ....?"), starting in about an hour. Bluntly, I think it's time to rally 'round the flag. http://chronicle.com/colloquylive/2003/08/opensource/chat.php Pass it on.
0
1400
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 a good third of my CPU time. there was another big hit that that was quick and easy. I went from approximately 3.5 seconds down to .5 seconds CPU time. The problem is, from hitting the submit button to new display, it is taking approximately 23...
6
12956
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...
3
1617
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 from one place to another. Is there any ASP scripts or DLLs(APIs) provided or sold by any third party mapping service? Have anyone come across such requirments? Your experience and suggestions will help me much.
17
7689
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 pages, some dating back so far I probably wrote them in vi. About 4 years ago (thanks in part to hints found in this group) I converted about 80 pages to CSS, and was fairly happy with the result, plain though they are. Since then I've forgotten...
43
2150
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 event (concert etc.), a player (of musical instruments), an ensemble (orchestra, band et al), an instrument.
4
2181
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 write the information about user name, filename upload, filesize, date and time of uploading into the log file. (The name of the log file is constructed by Current Year and Current Month in my program). Is there any problems with writing into the...
6
5165
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 U.S. (CST timezone -6). Note: daylight savings time _is_ observed in my state. I have looked all over a PHP algorithm that would convert GMT to CST but have so far not been successful. Does anyone have such an algorithm lying around that they could...
5
2208
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 Date Time 1 37 'Clockin' 1/18/08 7:45:39 AM 2 38 'Clockin' 1/18/08 7:55:42 AM 3 39 'Clockin' 1/18/08 7:55:42 AM 4 38 'BreakOut' 1/18/08 ...
27
5613
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
10618
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, 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...
0
10366
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 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...
1
10371
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
9187
agi2029
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...
0
6877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5546
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
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
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
3
3008
bsmnconsultancy
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...

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.