/    Sign up×
Community /Pin to ProfileBookmark

Programs with long runtime

When I run a Javascript program that needs a long run time, the system halts periodically with the message “a script in this program is causing your computer to run slowly …” and I have to click to restart the program. Is there a way of cancelling this facility, or of adjusting the time it allows before responding? This seems a simple question but I have not been able to find an answer. I have used IE7, IE8 and Chrome.

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@KorMar 26.2010 — When I run a Javascript program that needs a long run time, the system halts periodically with the message "a script in this program is causing your computer to run slowly ..." and I have to click to restart the program. Is there a way of cancelling this facility, or of adjusting the time it allows before responding? This seems a simple question but I have not been able to find an answer. I have used IE7, IE8 and Chrome.[/QUOTE]
That message tells you that your code is wrong and probably entered into and endless loop. You don't need to "cancel" the browser's message (after all, you can not do that). You must simply debug your code. The code is wrong, not the browser ?
Copy linkTweet thisAlerts:
@CaledonianauthorMar 26.2010 — No, the reply claiming my program must be in a loop is not correct. I have run programs that take a long time because they do a long exhaustive search, and when I keep them going by clicking on "no" every time the message appears, they finally terminate with a result. It can be very tedious and there should be a way of temporarily disabling the warning, but I haven't found it.
Copy linkTweet thisAlerts:
@Declan1991Mar 26.2010 — No, the reply claiming my program must be in a loop is not correct. I have run programs that take a long time because they do a long exhaustive search, and when I keep them going by clicking on "no" every time the message appears, they finally terminate with a result. It can be very tedious and there should be a way of temporarily disabling the warning, but I haven't found it.[/QUOTE]

You can change it in the settings in Firefox, but that won't be much good to you if you are writing for the web. The other choice is to optimize as much as possible, but that won't always help. Without code, we can't help you.
Copy linkTweet thisAlerts:
@mrhooMar 27.2010 — You can bring any computer to its knees with slow code-

you can also break up any code into shorter stretches

that won't trigger the script warning- but the code will take

even longer to complete.

Here is an example-

It looks for the largest prime number up to its argument,

and it uses a slow sifter, which helps this demonstration.

Most systems would throw the long-script warning before it got to a million.

But if you pause it every thousand numbers, it can catch its breath between times.

It uses a timeout to go back where it left off.

Eventually it will return the largest prime in the set.

Any long running function can store enough information between runs to do the same thing.

You will have to fiddle with the amount of work you do between timeouts.

You can update a progress bar on each cycle, deliver the final data someplace,

and signal when it's done.

This example took 751 seconds to return 9999991,

in a search for the largest prime under 10 million, without any warnings.

It took about 45 seconds to do a million, but your milage may vary.


[CODE]window.Memry=window.Memry || {};

Memry.highPrime=function(max){
if(max>Math.pow(2,53)) throw 'Don't be ridiculous.';
var F= arguments.callee;
var count= 0;
if(F.num=== undefined){
F.num= 2;
F.last= 2;
F.top= max;
F.time= new Date().getTime();
}
live= true;
while(F.num <= F.top && live){
div= 2;
prime= true;
while(div*div <= F.num){
if(F.num&#37;div=== 0){
prime= false;
break;
}
div++;
}
if(prime) F.last= F.num;
F.num++;
if(++count> 1000) live= false;
}
if(live){
F.num= undefined;
var t= ((new Date().getTime()-F.time)/1000).toFixed(3)+' seconds';
alert(F.last+'ntin '+t);
}
else{
setTimeout(F, 0);
}
}[/CODE]
[B]

Memry.highPrime(1000000);[/B]
Copy linkTweet thisAlerts:
@KorMar 27.2010 — No, the reply claiming my program must be in a loop is not correct. [/QUOTE]
OK. But my supposition that your program is not properly done remains. Maybe it is correct as syntax, but it is not correct by aim, analysis or efficiency. If the code suffocates the browser or the CPU, you should think seriously to change the code's paradigm.

After all: what kind of code is? What is it doing? Can you detail a little bit, please?
Copy linkTweet thisAlerts:
@CaledonianauthorMar 27.2010 — The reply by declan1991 solves my immediate problem. I hadn't tried Firefox and I now see it has the means of controlling the interruptions about long run time, as well as being faster than other browsers in running Javascript. Thanks, declan1991!
Copy linkTweet thisAlerts:
@KorMar 28.2010 — The reply by declan1991 solves my immediate problem. I hadn't tried Firefox and I now see it has the means of controlling the interruptions about long run time, as well as being faster than other browsers in running Javascript. Thanks, declan1991![/QUOTE]
It might have solved [I]your[/I] problem, but what about the users?
Copy linkTweet thisAlerts:
@svidgenMar 28.2010 — In general, if some client-side code needs to run in a browser "continuously" for an indefinite amount of time, you need to run things in chunks, each activate by a timeout set at the end of the previous chunk's execution.

Know what I mean?
×

Success!

Help @Caledonian spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...