[Javascript] How quick is quick ?

Allard Schripsema allard-schripsema at procergs.rs.gov.br
Tue Nov 9 11:57:51 CST 2004


Since this topic went off to performance i´d like to show you this small
code:
(based on the description tim gave us...
the first loop takes 1.7 secs on my computer, the 2nd 0.18,
Yet both do the same.
We all use the first kind of loop all of the time but never think about when
to optimize them.

I´ll let you figure out the math behind this one........

<html><head></head>
<script>
var now1
function Performance(description){
	var now2 = new Date()
	var miliSecs=now2.getTime()-now1.getTime()
	alert ( "JavaScript: "+description+"\n"+miliSecs/1000+" seconds. ")
}

now1 = new Date()

var bigString=""
for (var i=0; i<3000;i++){
	var bigString=bigString+ "line "+i+" of 3000"+"\r\n"
}
Performance("Loading BigString")

now1 = new Date()

var bigString2=""
for (var i=0; i<3000;i++){
	var smallstring ="line "+i+" of 3000"+"\r\n"
	bigString2=bigString2+smallstring
}
Performance("Loading smallString")
</script>
<body></body></html>


AnyBody has other tricks to share?

Allard Schripsema
-----Original Message-----
From: javascript-bounces at LaTech.edu
[mailto:javascript-bounces at LaTech.edu]On Behalf Of Laurent Muchacho
Sent: Tuesday, November 09, 2004 3:20 PM
To: '[JavaScript List]'
Subject: RE: [Javascript] How quick is quick ?


Hi

I use this it's pretty simple

put this variable at the beginning of you process or in the first js
var startLoad=new Date();

This one on the onload of the body or at the end of process
var endLoad=new Date();

alert('page loaded in : ' + (endLoad.getTime()-startLoad.getTime()) + '
millisecond');

Regards

Laurent

-----Original Message-----
From: Iztok Polanic [mailto:iztok.polanic at amis.net]
Sent: 09 November 2004 17:06
To: [JavaScript List]
Subject: RE: [Javascript] How quick is quick ?


Hi!

I don't have one, but it shouldn't be so hard to make one. How about getting
time before start and then again at the finish.

Bye,

Iztok (SLO)

> -----Original Message-----
> From: javascript-bounces at LaTech.edu
> [mailto:javascript-bounces at LaTech.edu]On Behalf Of Tim Makins
> Sent: 9. november 2004 17:36
> To: [JavaScript List]
> Subject: [Javascript] How quick is quick ?
>
>
> A few comments recently about how this will take time, and how
> that will be
> really slow.
>
> It would be nice to know exactly - has anyone got a routine that monitors
> the time a javascript routine takes to operate ??
>
> Tim in Ireland.
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript

_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript


This E-mail and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed.
If you have received this E-mail in error please notify the system manager.
This message contains confidential information and is intended only for the
individual named.  If you are not the named addressee you should not
disseminate, distribute or copy this E-mail.
_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript





More information about the Javascript mailing list