10

I want to benchmark some Javascript code in the browser, but it may trigger Firefox's "Warning: Unresponsive script" popup. This allows the user to click "Stop script" in the event that the browser is caught in a runaway function. While the pop-up is displayed, the currently running function has been halted. This isn't ideal, so is there a way to run my benchmarks differently such that Firefox doesn't popup this warning and ruin my results?

5 Answers 5

12

In firefox's address bar type about:config

You want to change dom.max_script_run_time to be large enough for your scripts to run.

2
  • 7
    Is he supposed to do that for every user of the page?
    – Oded
    Dec 16, 2009 at 20:22
  • 8
    He's using it for benchmarking--I don't think there are other users.
    – Annie
    Dec 16, 2009 at 20:23
9

You have to break up long actions into smaller ones and perform them in turns. This will also allow a better progress indication.

http://www.sonofsofaman.com/hobbies/code/settimeout.asp

3
  • 2
    Can you elaborate? A simple example, maybe?
    – spoulson
    Dec 16, 2009 at 20:25
  • Here's an example of using setTimeout to break up the running of the javascript: sonofsofaman.com/hobbies/code/settimeout.asp If you're doing benchmarks, make sure that you allow the code to run long enough to make up for the timer resolution. You'll probably want to read this: ejohn.org/blog/accuracy-of-javascript-time
    – Annie
    Dec 16, 2009 at 20:31
  • That link seems to be broken. Could you elaborate on how to do that in your answer?
    – Chris
    Oct 7, 2016 at 7:31
4

See in blog of Nicholas C. Zakas What determines that a script is long-running? (at 2009/01/05)

Speed up your JavaScript, Part 1 http://www.nczonline.net/blog/2009/01/13/speed-up-your-javascript-part-1/

there are the reasons and the ways how to avoid the dialog

2

You can use the script from this question to break processing long lists into smaller chunks:

How can I give control back (briefly) to the browser during intensive JavaScript processing?

0

The below code solved that problem for me...

<script type="text/javascript">
   function downloadJSAtOnload() {
   var element = document.createElement("script");
   element.src = "deferredfunctions.js";
   document.body.appendChild(element);
   }
   if (window.addEventListener)
   window.addEventListener("load", downloadJSAtOnload, false);
   else if (window.attachEvent)
   window.attachEvent("onload", downloadJSAtOnload);
   else window.onload = downloadJSAtOnload;
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.