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

Elapsed time

I'm trying to determine the amount of time that elapses between when
the page starts loading and after all of the javascript is done
running. Right now I have in the header something like:

var start = new Date();

and then after the last javascript call I have:

var end = new Date();
var elapsedTimeInMilliseconds = end - start;
report(elapsedTimeInMilliseconds);

the report function sends the value back to the server.

This is working fine for me, but the report that is coming back from
the back-end containing all 500,000 or so hits to the page contains
some preposterously high numbers and also even some negative numbers.
Am I doing something wrong here? Can anyone think of a reason this
wouldn't be working, or how I could possibly get a negative value?

Thanks so much in advance!

-Duane
Jan 9 '08 #1
6 2337
duane.barlow wrote:
I'm trying to determine the amount of time that elapses between when
the page starts loading and after all of the javascript is done
running. Right now I have in the header something like:

var start = new Date();

and then after the last javascript call I have:

var end = new Date();
var elapsedTimeInMilliseconds = end - start;
You don't need `end':

var elapsedTimeInMilliseconds = new Date() - start;

For that matter, you don't need `elapsedTimeInMilliseconds' either.
report(elapsedTimeInMilliseconds);
report(new Date() - start);
the report function sends the value back to the server.

This is working fine for me, but the report that is coming back from
the back-end containing all 500,000 or so hits to the page contains
some preposterously high numbers and also even some negative numbers.
Am I doing something wrong here? Can anyone think of a reason this
wouldn't be working, or how I could possibly get a negative value?
You could get a negative value when your site happens to be loading between
a system clock modification on the client. That could be a general clock
correction, even an automated one using an NTP server. Looks like as if you
should log the timestamps as well.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Jan 10 '08 #2
On Jan 9, 2:32 pm, "duane.barlow" <duane.bar...@gmail.comwrote:
I'm trying to determine the amount of time that elapses between when
the page starts loading and after all of the javascript is done
running. Right now I have in the header something like:
If you're not already, I would suggest logging the user agent string
and IP address with these data. You might find a correlation between
a particular client configuration (or specific clients) and the bogus
values. Hopefully this extra info will elucidate the cause.

The negative values (if they're small) are probably due to an NTP
driven system clock change (as mentioned by Thomas).
Jan 10 '08 #3
jh******@gmail.com said the following on 1/10/2008 1:04 AM:
On Jan 9, 2:32 pm, "duane.barlow" <duane.bar...@gmail.comwrote:
>I'm trying to determine the amount of time that elapses between when
the page starts loading and after all of the javascript is done
running. Right now I have in the header something like:

If you're not already, I would suggest logging the user agent string
and IP address with these data. You might find a correlation between
a particular client configuration (or specific clients) and the bogus
values. Hopefully this extra info will elucidate the cause.

The negative values (if they're small) are probably due to an NTP
driven system clock change (as mentioned by Thomas).
It took me a while to find that setting and realize that it was the
source of a lot of frustration for me doing timed items with the clock
set to auto-update itself.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 10 '08 #4
In comp.lang.javascript message <ce95a30a-3a6f-48b2-a956-86f02d614201@q3
9g2000hsf.googlegroups.com>, Wed, 9 Jan 2008 14:59:55, duane.barlow
<du**********@gmail.composted:
>The strange thing is that almost all of the numbers make sense except
sometimes there is an enormous number of milliseconds that equates to
like 300 years.. It goes without saying that the page hadn't been
loading that long, but how could that number be getting reported? Is
it incorrect to subtract two date objects directly, should i be doing
end.getTime() - start.getTime()?
There should be no problem with that subtraction.

After digesting the newsgroup FAQ section 2.3, you should report the
exact number of milliseconds, and where known the OS and browser
combination in which it was seen.

300 years is usually 9467107200000 ms, otherwise 9467020800000 ms; about
9.5e12 ms.

You might have a server or analysis problem.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jan 10 '08 #5
Dr J R Stockton wrote on 10 jan 2008 in comp.lang.javascript:
>>it incorrect to subtract two date objects directly, should i be doing
end.getTime() - start.getTime()?

There should be no problem with that subtraction.
Except when passing local midnight during the measurement.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 11 '08 #6
In comp.lang.javascript message <Xn********************@194.109.133.242>
, Fri, 11 Jan 2008 09:14:37, Evertjan. <ex**************@interxnl.net>
posted:
>Dr J R Stockton wrote on 10 jan 2008 in comp.lang.javascript:
>>>it incorrect to subtract two date objects directly, should i be doing
end.getTime() - start.getTime()?

There should be no problem with that subtraction.

Except when passing local midnight during the measurement.
There should be no problem with that subtraction.

x = [+new Date(), new Date().valueOf(), new Date().getTime()]

- 1200069319625,1200069319625,1200069319625 (in IE6; FF2 Op9 akin)

However. methods .getTimeOnly(), .getUTCTimeOnly() could be a useful
addition to the Date Object; also .getDateOnly(), .getUTCDateOnly().

I wonder whether the *original* intention was for .getTime() and
..valueOf() to differ !

CAVEAT : Safari 3.0.4 : it seems that a Date Object can be set to a
value above the lawful range. The code

D = new Date(864e5*(1e8-1)) ; D.setDate(22) ; X = D/864e5

gives 100000009 in Safari, but NaN in IE6 IE7 FF2 Op9. Reported.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jan 11 '08 #7

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

Similar topics

1
by: NotGiven | last post by:
Below is a good elapsed time function I found. However, I'd like to return total seconds instead of broken down into days, hours, minutes & seconds. In other words, I want "125" instead of "2...
11
by: Philip Wagenaar | last post by:
Hello, I am using a timer object in my Windows Forms Application. Does the code in ..elapsed event run in a diffrent thread? If the interval is set to 10 milliseconds and the time to execute the...
20
by: Jean Johnson | last post by:
Hello - I have a start and end time that is written using the following: time.strftime("%b %d %Y %H:%M:%S") How do I calculate the elapsed time? JJ
4
by: Liverpool fan | last post by:
I have a windows application written using VB .NET that encompasses a countdown timer modal dialog. The timer is a System.Timers.Timer with an interval of 1 second. AutoReset is not set so accepts...
4
by: Jim in Arizona | last post by:
I want to make buttons available or not available based on how much time has elapsed. An example: If NOW() 8 hours then btnOne.Visible = False Thanks. Jim
12
by: Spitfire | last post by:
I've a requirement to find the elapsed time between two function calls. I need to find the time elapsed accurate to 1 millisecond. The problem I'm facing right now is that, I'm using the 'time()'...
5
by: mmi48 | last post by:
Most of the discussions I've seen about elapsed time have, thus far, involved at least two date/time fields. I am trying to calculate time elapsed from one field across multiple records. The field...
12
by: pekka | last post by:
I'm trying to measure user input time with my Timer class object. It isn't as easy as I expected. When using std::cin between timer start and stop, I get zero elapsed time. For some unknown reason,...
7
by: wanwan | last post by:
Hi, I'm looking for a better way to do a date/time elapsed event rather than a timer elapsed event. Currently, I wrote my program to use a timer elapsed event set to 1 second, and it checks...
9
by: Ross | last post by:
I'm a newbie at this, and have searched a lot but can't find something that seems appropriate for measuring a recurring elapsed time. Creating an object with: var mydate = new Date(); seems...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.