472,811 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,811 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 1599
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,...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.