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

javascript timers doubt

Hi All,

1 ) I am using the Date() function to get the current time. But it
doesnt tell me the time value in millisec. Is there any API in
javascript that returns the current time value with resolution in
millisec

2) Also i see the setTimeout value does not get expired at the correct
time. I see some delay there. Is there any way to avoid this.
3)When the javascript timer callback is getting executed, will there be
a context switching that can happen without finishing the
timercallback..I have added timestamp to the start and end of my timer
callback. But it doesnt give me a constant response for the same
operation. Sometimes it takes 1 sec, and sometime it takes around 6
sec..

Thanks

Aug 8 '05 #1
7 1632
1. Use DateObject.getTime() and .getMilliseconds() method

2. setTimeout() do not return expired time - this function set "system timer" to given timeout. Using JavaScript for "realtime" may be wrong.

3. JavaScript - browser-inside interpreter. Results may be different with same code at different browsers.
Aug 8 '05 #2
va*********@gmail.com wrote:
Hi All,

1 ) I am using the Date() function to get the current time. But it
doesnt tell me the time value in millisec. Is there any API in
javascript that returns the current time value with resolution in
millisec
Have a browse of the stuff here:

<URL:http://www.merlyn.demon.co.uk/js-date0.htm#TaI>

and here:

<URL:http://www.merlyn.demon.co.uk/js-dates.htm#SDT>

There is also somewhere there a spot that tells you the update
interval of the internal clock - the Windows (XP & 2000) machines I
use tend to update at 15 or 16 millisecond intervals, Mac OS at 1 ms
intervals.

2) Also i see the setTimeout value does not get expired at the correct
time. I see some delay there. Is there any way to avoid this.
3)When the javascript timer callback is getting executed, will there be
a context switching that can happen without finishing the
timercallback..I have added timestamp to the start and end of my timer
callback. But it doesnt give me a constant response for the same
operation. Sometimes it takes 1 sec, and sometime it takes around 6
sec..


It may be important (or not) that setTimeout and setInterval are not
part of ECMAScript Language but are provided by the browser window
object.

--
Rob
Aug 8 '05 #3
Hi,
Thanks for your reply. I am not clear of the context switching. While
in the timer callback,can a context switching happen without completing
the callback.?

Aug 8 '05 #4
JRS: In article <42f71210$0$16486$5a62ac22@per-qv1-newsreader-
01.iinet.net.au>, dated Mon, 8 Aug 2005 18:04:31, seen in
news:comp.lang.javascript, RobG <rg***@iinet.net.auau> posted :

<URL:http://www.merlyn.demon.co.uk/js-dates.htm#SDT>

There is also somewhere there a spot that tells you the update
interval of the internal clock - the Windows (XP & 2000) machines I
use tend to update at 15 or 16 millisecond intervals, Mac OS at 1 ms
intervals.


Now
<URL:http://www.merlyn.demon.co.uk/js-dates.htm#Ress> or scan for RobG .

I'd be pleased to have interval and resolution data for other (common)
systems.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Aug 8 '05 #5
Dr John Stockton wrote:
[...]

Now
<URL:http://www.merlyn.demon.co.uk/js-dates.htm#Ress> or scan for RobG .

I'd be pleased to have interval and resolution data for other (common)
systems.


OK, here's some results. Mac OS 9 was done in classic mode under OS
X, I couldn't get results from Communicator (version 4.7) it just kept
crashing. I may update the version and try again later.

System Browser Update Resolution

Mac OS X Safari 1.5 1
Firefox 4.8 1
IE 1 1
Mac OS 9 IE 2.1 1
Netscape 4.7 - crashed.

Win2k Pro Firefox 16 1
IE 10 1

--
Rob
Aug 9 '05 #6
Re context switching. The short answer, as far as I have been able to
ascertain is NO, there is never context switching in execution of
setInterval and setTimeOut. The event engine (in the browser) is
single threaded. The interval in setTimeOut is more like a suggestion
than a fact. If the engine takes longer than the specified time to get
back to it's idle loop then that is when your callback will be
executed.
Bob

Aug 9 '05 #7
JRS: In article <42f7fc38$0$32245$5a62ac22@per-qv1-newsreader-
01.iinet.net.au>, dated Tue, 9 Aug 2005 10:43:27, seen in
news:comp.lang.javascript, RobG <rg***@iinet.net.auau> posted :
Dr John Stockton wrote:
[...]

Now
<URL:http://www.merlyn.demon.co.uk/js-dates.htm#Ress> or scan for RobG .

I'd be pleased to have interval and resolution data for other (common)
systems.


OK, here's some results. Mac OS 9 was done in classic mode under OS
X, I couldn't get results from Communicator (version 4.7) it just kept
crashing. I may update the version and try again later.

System Browser Update Resolution

Mac OS X Safari 1.5 1
Firefox 4.8 1
IE 1 1
Mac OS 9 IE 2.1 1
Netscape 4.7 - crashed.

Win2k Pro Firefox 16 1
IE 10 1


Thanks : I've included those in the Table.

My Win98 system should average interval 864E5/0x1800B0 = 54.9; I believe
that those showing 15 or 16 average 15.625 = 1/64, and that 10 is exact.
Other figures nave no obvious explanation.

I've also made provision for using other numbers of loops in the testing
- but IIRC the line containing N = +Num.value will need upgrading
for some systems : suggestions?

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Aug 9 '05 #8

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

Similar topics

1
by: Antoine | last post by:
Hello, Does anybody know a way to retreive the running timers (their ids) in a html page? I cannot find something in the html dom at first sight. Is there collection of timers available (like...
0
by: Dmitry Demchuk | last post by:
Hi everybody. Recently I ran into situation with System.Threading.Timer in my ASP.NET application. I reinstalled Windows on one of my servers and got timers stop firing events after while, they...
9
by: Mark Rae | last post by:
Hi, I've seen several articles about using System Timers in ASP.NET solutions, specifically setting them up in Global.asax' Application_OnStart event. I'm thinking about the scenario where I...
10
by: Chris Lieb | last post by:
Hi, I am working on an object that has a function that calls setInterval so that it can have a function called repeatedly. Right now, to call the function, you also have to provide the name of...
1
by: | last post by:
Frustrated.. (I have seen other posts regarding this problem with no resolution..) I am using dotnet 1.1 with latest SP on a Win2KP box (actually 2 boxes), have even run the service on WinXP SP2...
1
by: Jonathan Woods | last post by:
Hi there, I have three methods these need to execute at every interval time. I would like to know which option is better? Option A) Three System.Timers.Timer objects these execute each...
8
by: jayender.vs | last post by:
Well .. i have a text box .. and in that i will enter a letter say"A" and in return there should be a message box saying the encrypted value say "J". In simple : how to encrypt a letter in...
7
by: Marina Levit [MVP] | last post by:
Does anyone knows if this exists? Basically, a way to tell a method to execute, but a certain amount of time after the current event chain is finished - not immediately. With setTimeout, even if it...
0
by: hendyhanusin | last post by:
Dear all, Pls help in JavaScript coding since i'm a beginner in JavaScript . i have a .NET class library (DLL) : ACR120DLL.ACR120DLL... Does anybody know how to use this DLL event (AddList,...
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
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
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:
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...
0
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...
0
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,...
0
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...
0
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...

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.