Author: Graham Laight
Date: 13:52:52 01/03/03
Go up one level in this thread
On January 03, 2003 at 07:52:46, Graham Laight wrote:
I've just tried the code below on an old computer at home running IE 5.0, and it
threw up an unexpected error which I've highlighted below. Perhaps someone with
more JavaScript experience than me (I'm learning it for my job) would like to
comment?
><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
>
><html>
><head>
><title>Graham's Optimisation Demo</title>
></head>
><body>
><SCRIPT LANGUAGE="JavaScript">
>function easyToMaintain()
>{
> var R = new Array();
> R[0] = 1;
> R[1] = 2;
> R[2] = 3;
>
> var p = 0;
> var startTime = new Date();
>
> for (k = 0; k < 1000000; k++)
> {
> if((R[1]==3)||(R[1]==7))
> p = p + 1;
> }
>
> var endTime = new Date();
> var totalTime = endTime.getTime() - startTime.getTime();
> alert("The easy to maintain version took " + totalTime + " milliseconds to
>run");
Here. The CCC text editor has wrapped my quoted text onto 2 lines, which caused
an error (in IE5, to see a JavaScript error, click on the icon on the very
bottom left of the IE window after the error has occured).
Spacing and line breaks are supposed to be unimportant in JavaScript -
presumably the problem is that the line break occurs in the middle of a quoted
text string.
>}
>
>function possiblyQuicker()
>{
> var R = new Array();
> R[0] = 1;
> R[1] = 2;
> R[2] = 3;
>
> var p = 0;
> var x = 0;
> var startTime = new Date();
>
> for (k = 0; k < 1000000; k++)
> {
> x = R[1];
> if((x==3)||(x==7))
> p = p + 1;
> }
>
> var endTime = new Date();
> var totalTime = endTime.getTime() - startTime.getTime();
> alert("The potentially quicker version took " + totalTime + " milliseconds to
>run");
Same problem here.
-g
>}
>
></SCRIPT>
><input type="button" value="Test Easy-To-Maintain Version Of Code"
>onclick="easyToMaintain()">
><input type="button" value="Test Possibly-Quicker Version Of Code"
>onclick="possiblyQuicker()">
></body>
></html>
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.