By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,712 Members | 2,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,712 IT Pros & Developers. It's quick & easy.

can javascript get tenths of a second

P: n/a
Guy
I would like to calculate the time it takes to load a picture in tenths of a
seconds. So I get the current time, load the image, and once loaded I get
the current time again.

I would like to know if it took 9.3 seconds or 9.7 seconds or whatever.

Can javascript get tenths of a second.

Thanks for all,
Guy

My current HTML document looks like this:
The calculation is based on the size of the file I was using.
<HTML>
<HEAD>
<META Http-Equiv="Cache-Control" Content="no-cache">
<META Http-Equiv="Cache-Control" Content="max-age=0">
<META Http-Equiv="Pragma" Content="no-cache">
<META Http-Equiv="Expires" Content="0">

<SCRIPT language=javascript>

var a;
var b;
var c;
var d;
var e;
var h;
var m;
var s;
var n;

n=0;

function gettime()
{
var t = new Date();
h = t.getHours();
m = t.getMinutes();
s = t.getSeconds();
}
function begin()
{
self.document.f1.i5.value='Testing...';
gettime();
a=s;
self.document.f1.i1.value=h + ":" + m + ":" + s;
self.document.f1.i2.value='';
if(n==0){n=1;self.document.pic.src='e1.gif';}
else{n=0;self.document.pic.src='e2.gif';}
}
function calc()
{
gettime();
b=s;
self.document.f1.i2.value=h + ":" + m + ":" + s;
if((b-a)<0){b=b+60;}
c=(b-a);
if(c<2)
{
d="";
e="";
self.document.f1.i5.value='You must delete your temporary Internet
Files';
}
else
{
d=Math.round(15994310/(c*1024))/10;
e=Math.round(15994310/c)/10;
self.document.f1.i5.value='Done!';
}
self.document.f1.i3.value=d;
self.document.f1.i4.value=e;
}
</SCRIPT>
</HEAD>

<BODY>
<CENTER>
<FORM name=f1>
<TABLE border=1><TR><TD align=center>
<BR>
<FONT SIZE=4>Trial Speed-Test site</FONT><BR><BR>
<TABLE cellspacing=0 cellpadding=2 border=0>
<TR><TD>Start time </TD><TD><INPUT name='i1' value=''>
</TD></TR>
<TR><TD>End Time </TD><TD><INPUT name='i2' value=''>
</TD></TR>
<TR><TD>Speed </TD><TD><INPUT name='i3' value=''> kilobytes per second
</TD></TR>
<TR><TD> </TD><TD><INPUT name='i4' value=''> Bytes per second
</TD></TR>
</TABLE>
<BR>
<IMG name='test' width=100 height=100 border=1 src='test.gif'
onclick='self.begin();'>
<BR><BR>
<INPUT name='i5' value='' size=50>
<IMG name='pic' width=0 height=0 border=0 src='' onload='self.calc();'>
</TD></TR></TABLE>
</FORM>

</CENTER>
</BODY>
</HTML>

Jul 20 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
Lee
Guy said:

I would like to calculate the time it takes to load a picture in tenths of a
seconds. So I get the current time, load the image, and once loaded I get
the current time again.

I would like to know if it took 9.3 seconds or 9.7 seconds or whatever.

Can javascript get tenths of a second.


var beginTime=new Date();
doSomething();
var endTime=new Date();
ver difference=endTime.getTime()-beginTime.getTime();

difference will be in thousands of a second.

Jul 20 '05 #2

P: n/a
Guy wrote:
I would like to calculate the time it takes to load a picture in tenths of a
seconds. So I get the current time, load the image, and once loaded I get
the current time again.

I would like to know if it took 9.3 seconds or 9.7 seconds or whatever.

Can javascript get tenths of a second.

Thanks for all,
Guy

My current HTML document looks like this:
The calculation is based on the size of the file I was using.
<HTML>
<HEAD>
<META Http-Equiv="Cache-Control" Content="no-cache">
<META Http-Equiv="Cache-Control" Content="max-age=0">
<META Http-Equiv="Pragma" Content="no-cache">
<META Http-Equiv="Expires" Content="0">

<SCRIPT language=javascript>

var a;
var b;
var c;
var d;
var e;
var h;
var m;
var s;
var n;

n=0;

function gettime()
{
var t = new Date();
h = t.getHours();
m = t.getMinutes();
s = t.getSeconds();
}
function begin()
{
self.document.f1.i5.value='Testing...';
gettime();
a=s;
self.document.f1.i1.value=h + ":" + m + ":" + s;
self.document.f1.i2.value='';
if(n==0){n=1;self.document.pic.src='e1.gif';}
else{n=0;self.document.pic.src='e2.gif';}
}
function calc()
{
gettime();
b=s;
self.document.f1.i2.value=h + ":" + m + ":" + s;
if((b-a)<0){b=b+60;}
c=(b-a);
if(c<2)
{
d="";
e="";
self.document.f1.i5.value='You must delete your temporary Internet
Files';
}
else
{
d=Math.round(15994310/(c*1024))/10;
e=Math.round(15994310/c)/10;
self.document.f1.i5.value='Done!';
}
self.document.f1.i3.value=d;
self.document.f1.i4.value=e;
}
</SCRIPT>
</HEAD>

<BODY>
<CENTER>
<FORM name=f1>
<TABLE border=1><TR><TD align=center>
<BR>
<FONT SIZE=4>Trial Speed-Test site</FONT><BR><BR>
<TABLE cellspacing=0 cellpadding=2 border=0>
<TR><TD>Start time </TD><TD><INPUT name='i1' value=''>
</TD></TR>
<TR><TD>End Time </TD><TD><INPUT name='i2' value=''>
</TD></TR>
<TR><TD>Speed </TD><TD><INPUT name='i3' value=''> kilobytes per second
</TD></TR>
<TR><TD> </TD><TD><INPUT name='i4' value=''> Bytes per second
</TD></TR>
</TABLE>
<BR>
<IMG name='test' width=100 height=100 border=1 src='test.gif'
onclick='self.begin();'>
<BR><BR>
<INPUT name='i5' value='' size=50>
<IMG name='pic' width=0 height=0 border=0 src='' onload='self.calc();'>
</TD></TR></TABLE>
</FORM>

</CENTER>
</BODY>
</HTML>


Look in the manual for Date:

http://devedge.netscape.com/library/...e.html#1193137

You can get milliseconds.

Jul 20 '05 #3

P: n/a
JRS: In article <br*********@drn.newsguy.com>, seen in
news:comp.lang.javascript, Lee <RE**************@cox.net> posted at Sat,
13 Dec 2003 10:28:27 :-
Guy said:

I would like to calculate the time it takes to load a picture in tenths of a
seconds. So I get the current time, load the image, and once loaded I get
the current time again.

I would like to know if it took 9.3 seconds or 9.7 seconds or whatever.

Can javascript get tenths of a second.


var beginTime=new Date();
doSomething();
var endTime=new Date();
ver difference=endTime.getTime()-beginTime.getTime();

difference will be in thousands of a second.


Not really. Well, it will be an integer number of thousandths, but it
is not likely to have a resolution of one of those.

AIUI, in DOS..Win98, resolution is about 55 ms; in WinNT+ it is 10 ms.

However, it may depend on browser, on OS, and even on CPU. RSVP. To
test your system, execute the following with the Eval button in
<URL:http://www.merlyn.demon.co.uk/js-quick.htm> or otherwise.

var J, T, XT=0, XXT

J = 0 ; XXT = T = new Date().getTime()

while (J <= 10) {
if (T != XT) { XT = T ; J++ }
T = new Date().getTime() }

"On your system, it measures at about " +
(new Date() - XXT)/10 + " ms less possible overheads."
Mr bagbourne should read the FAQ; to learn about trimming quotes, and to
learn some facts about javascript.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> Jsc maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/Jsc/&c, FAQ topics, links.
Jul 20 '05 #4

P: n/a
Lee
Dr John Stockton said:

JRS: In article <br*********@drn.newsguy.com>, seen in
news:comp.lang.javascript, Lee <RE**************@cox.net> posted at Sat,
13 Dec 2003 10:28:27 :-
Guy said:

I would like to calculate the time it takes to load a picture in tenths of a
seconds. So I get the current time, load the image, and once loaded I get
the current time again.

I would like to know if it took 9.3 seconds or 9.7 seconds or whatever.

Can javascript get tenths of a second.


var beginTime=new Date();
doSomething();
var endTime=new Date();
ver difference=endTime.getTime()-beginTime.getTime();

difference will be in thousands of a second.


Not really. Well, it will be an integer number of thousandths, but it
is not likely to have a resolution of one of those.


Yes, really. The difference will be in thousands of a second.
It will not be accurate to 1 thousandth of a second, but that
is the unit that is reported.

Jul 20 '05 #5

P: n/a
bagbourne wrote:
[1 attribution line]
[1 blank line]
[131 lines of fullquote]
[1 blank line]
[6 lines of new text]


You may want to trim your quotes next time:
<http://www.netmeister.org/news/learn2quote2.html>

Besides:

| [20:15:51] pointedears:~ $ host -t mx noway.com
| Server: 193.189.244.205
| Address: 193.189.244.205#53
|
| ** server can't find noway.com: SERVFAIL

By using a faked e-mail address you prevent yourself from getting
spam, but at the same time you help to destroy the Internet. Due
to the egotistical behavior you display with such, I will not
download your postings anymore until you change that. See
<http://www.interhack.net/pubs/munging-harmful/> for details.
PointedEars
Jul 20 '05 #6

P: n/a
Lee
Thomas 'PointedEars' Lahn said:
By using a faked e-mail address you prevent yourself from getting
spam, but at the same time you help to destroy the Internet. Due
to the egotistical behavior you display with such, I will not
download your postings anymore until you change that. See
<http://www.interhack.net/pubs/munging-harmful/> for details.


How do you suppose these rank in terms of harming the usefulness
of the Internet:
1) Using a false email address
2) Spam
3) Constantly nagging people who use false addresses

I would put using a false address last, personally.
The "functionality" that is lost is not an important feature.
I first stopped using an email address that I actually read
when I started getting too much personal email from people in
newsgroups, not because of spam.

Jul 20 '05 #7

P: n/a
Guy
Ok, from your postings, I assume your not a spam artist looking to add my
email to a spam list! :-)

But from what I understand, newsgroups are desinged for people to share on
the newsgroup and not by email. I wouldn't expect someone to mail me an
answer, nor would I email someone an answer. For one thing, it's possible
that my answer may be wrong and by posting it, people can correct me.

And I'm definitely not going to hand over my email address to spammers. The
Internet is being slowed down enough by junk mail, including messages asking
you to email as many friends as you know to get money from microsoft and
AOL, and then I get about 20 emails from people I thought were smart! So
actually, I think that by not including my email address I am doing the
opposite of destroying the Internet.

But since you asked, does anyone know of a safe way to give out your email
address in a posting without any spammers picking it up?

Trying to do the right thing,

Guy
"Thomas 'PointedEars' Lahn" <Po*********@web.de> wrote in message
news:3F**************@PointedEars.de...
bagbourne wrote:
[1 attribution line]
[1 blank line]
[131 lines of fullquote]
[1 blank line]
[6 lines of new text]


You may want to trim your quotes next time:
<http://www.netmeister.org/news/learn2quote2.html>

Besides:

| [20:15:51] pointedears:~ $ host -t mx noway.com
| Server: 193.189.244.205
| Address: 193.189.244.205#53
|
| ** server can't find noway.com: SERVFAIL

By using a faked e-mail address you prevent yourself from getting
spam, but at the same time you help to destroy the Internet. Due
to the egotistical behavior you display with such, I will not
download your postings anymore until you change that. See
<http://www.interhack.net/pubs/munging-harmful/> for details.
PointedEars

Jul 20 '05 #8

P: n/a
> >By using a faked e-mail address you prevent yourself from getting
spam, but at the same time you help to destroy the Internet.

I used to believe that. That was the advice of many elders in the ciwa*
(particularly html) groups.Then my spam load hit 300+/day. At that point I
no longer cared if the internet functioned because I couldn't.

Usenet denizens are particularly badly hit by SPAM harvesters, and you have
to take some steps to avoid that. I really don't know what the best approach
is although it probably isn't mine!

Cheers,
Jeff

Jul 20 '05 #9

P: n/a
Jeff Thies wrote:
>By using a faked e-mail address you prevent yourself from getting
>spam, but at the same time you help to destroy the Internet.

I used to believe that. That was the advice of many elders in the ciwa*
(particularly html) groups.Then my spam load hit 300+/day. At that point I
no longer cared if the internet functioned because I couldn't.

Usenet denizens are particularly badly hit by SPAM harvesters,


Undoubtedly. I get many spam mails -- but the most of it is filtered
server-side before I need to download it or it blocks my mailbox. The
rest (about 10 per day) is filtered client-side by Mozilla's Junk Mail Controls.
and you have to take some steps to avoid that.
Definitely, see above.
I really don't know what the best approach is
Maybe using filters? Maybe complaining to the ISPs by mail so that *they*
stop spammers, by removing their accounts and by closing open relays?
although it probably isn't mine!


Well, consider yourself killfiled then. Null problemo.
PointedEars
Jul 20 '05 #10

P: n/a
In article <br************@ID-107532.news.uni-berlin.de>, Thomas 'PointedEars'
Lahn <Po*********@web.de> writes:
Jeff Thies wrote:
>By using a faked e-mail address you prevent yourself from getting
>spam, but at the same time you help to destroy the Internet.


I used to believe that. That was the advice of many elders in the ciwa*
(particularly html) groups.Then my spam load hit 300+/day. At that point I
no longer cared if the internet functioned because I couldn't.

Usenet denizens are particularly badly hit by SPAM harvesters,


Undoubtedly. I get many spam mails -- but the most of it is filtered
server-side before I need to download it or it blocks my mailbox. The
rest (about 10 per day) is filtered client-side by Mozilla's Junk Mail
Controls.


So, because I get spam mail from Newsgroups, I should manage it on my end? One
method of managing it is <gasp> not giving out a correct email address. Imagine
that.
and you have to take some steps to avoid that.


Definitely, see above.
I really don't know what the best approach is


Maybe using filters? Maybe complaining to the ISPs by mail so that *they*
stop spammers, by removing their accounts and by closing open relays?


And one potential filter is to not give out the address. Mine is not munged,
but its because I don't care. I don't recieve internet email (compliments of
AOL mail filters) so its a non-issue to me.

But anybody that continuously complains about email addresses, attribute lines
and signatures has more time on there hands than they need.
although it probably isn't mine!


Well, consider yourself killfiled then. Null problemo.


Can I join him? There are a few here that I wonder if they have killfiled me,
but rest assured you are not one of them.

P.S. Can you *please* explain how using a fake email address "helps destroy the
internet"? The internet was *not* developed as a mail system. Far from it.
--
Randy
Jul 20 '05 #11

P: n/a
JRS: In article <xk***************@newsread3.news.atl.earthlink.ne t>,
seen in news:comp.lang.javascript, Jeff Thies <no****@nospam.net> posted
at Fri, 19 Dec 2003 13:48:13 :-
>By using a faked e-mail address you prevent yourself from getting
>spam, but at the same time you help to destroy the Internet.


I used to believe that. That was the advice of many elders in the ciwa*
(particularly html) groups.Then my spam load hit 300+/day. At that point I
no longer cared if the internet functioned because I couldn't.


Ignore Thomas Lahn; he's a twerp, who thinks he understands what is
going on.. He'll have kill-filed everybody before long.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 20 '05 #12

P: n/a
Lee
Thomas 'PointedEars' Lahn said:
Undoubtedly. I get many spam mails -- but the most of it is filtered
server-side before I need to download it or it blocks my mailbox. The
rest (about 10 per day) is filtered client-side by Mozilla's Junk Mail Controls.
If you're filtering out all spam, then you're almost certainly
also filtering out some legitmate email. That's a price that
I'm not eager to pay.
Maybe using filters? Maybe complaining to the ISPs by mail so that *they*
stop spammers, by removing their accounts and by closing open relays?


So I should spend additional time sending email to ISP's, in
hopes that I can motivate them to stop taking somebody's money,
because they have offended me?

Jul 20 '05 #13

P: n/a
"Guy" <so*****@somewhere.nb.ca> wrote in message news:<Wt********************@ursa-nb00s0.nbnet.nb.ca>...
I would like to calculate the time it takes to load a picture in tenths of a
seconds. So I get the current time, load the image, and once loaded I get
the current time again.

I would like to know if it took 9.3 seconds or 9.7 seconds or whatever.

Can javascript get tenths of a second.

Thanks for all,
Guy

My current HTML document looks like this:
The calculation is based on the size of the file I was using.
<HTML>
<HEAD>
<META Http-Equiv="Cache-Control" Content="no-cache">
<META Http-Equiv="Cache-Control" Content="max-age=0">
<META Http-Equiv="Pragma" Content="no-cache">
<META Http-Equiv="Expires" Content="0">

<SCRIPT language=javascript>

var a;
var b;
var c;
var d;
var e;
var h;
var m;
var s;
var n;

n=0;

function gettime()
{
var t = new Date();
h = t.getHours();
m = t.getMinutes();
s = t.getSeconds();
}
function begin()
{
self.document.f1.i5.value='Testing...';
gettime();
a=s;
self.document.f1.i1.value=h + ":" + m + ":" + s;
self.document.f1.i2.value='';
if(n==0){n=1;self.document.pic.src='e1.gif';}
else{n=0;self.document.pic.src='e2.gif';}
}
function calc()
{
gettime();
b=s;
self.document.f1.i2.value=h + ":" + m + ":" + s;
if((b-a)<0){b=b+60;}
c=(b-a);
if(c<2)
{
d="";
e="";
self.document.f1.i5.value='You must delete your temporary Internet
Files';
}
else
{
d=Math.round(15994310/(c*1024))/10;
e=Math.round(15994310/c)/10;
self.document.f1.i5.value='Done!';
}
self.document.f1.i3.value=d;
self.document.f1.i4.value=e;
}
</SCRIPT>
</HEAD>

<BODY>
<CENTER>
<FORM name=f1>
<TABLE border=1><TR><TD align=center>
<BR>
<FONT SIZE=4>Trial Speed-Test site</FONT><BR><BR>
<TABLE cellspacing=0 cellpadding=2 border=0>
<TR><TD>Start time </TD><TD><INPUT name='i1' value=''>
</TD></TR>
<TR><TD>End Time </TD><TD><INPUT name='i2' value=''>
</TD></TR>
<TR><TD>Speed </TD><TD><INPUT name='i3' value=''> kilobytes per second
</TD></TR>
<TR><TD> </TD><TD><INPUT name='i4' value=''> Bytes per second
</TD></TR>
</TABLE>
<BR>
<IMG name='test' width=100 height=100 border=1 src='test.gif'
onclick='self.begin();'>
<BR><BR>
<INPUT name='i5' value='' size=50>
<IMG name='pic' width=0 height=0 border=0 src='' onload='self.calc();'>
</TD></TR></TABLE>
</FORM>

</CENTER>
</BODY>
</HTML>

Ok. You can do some math to convert the milliseconds to tenths of a
second. You could use Math.floor and divide by 100. That would give
you tenths of a second.
Jul 20 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.