Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6700275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:47:42+00:00 2026-05-26T06:47:42+00:00

the following test is basically ~1000 math operations and works fine on most PC

  • 0

the following test is basically ~1000 math operations and works fine on most PC and android browsers, and iOS 4.x. On iOS5 safari (iPhone 4 and iPad 2) we get “JavaScript: Error undefined JavaScript execution exceeded timeout”. Any help greatly appreciated thanks.

/** Converts numeric degrees to radians */
if (typeof (Number.prototype.toRad) === "undefined") {
    Number.prototype.toRad = function () {
    return this * Math.PI / 180;
    }
}

function gc(lat1, lon1, lat2, lon2) {
    // returns the distance in km between a pair of latitude and longitudes
    var R = 6371; // km
    var dLat = (lat2 - lat1).toRad();
    var dLon = (lon2 - lon1).toRad();
    var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
        Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) *
        Math.sin(dLon / 2) * Math.sin(dLon / 2);
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    var d = R * c;
    return d;
}

function test() {
    var d1 = new Date();
    var lat1, lon1, lat2, lon2;
    lat1 = -36;
    lon1 = 174;

    lat2 = lat1;
    lon2 = lon1;

    while (lat2 > -37) {
    lat2 = lat2 - 0.001;
    var stest = "lat1=" + lat1 + ",lon1=" + lon1 + ",lat2=" + lat2 + ",lon2=" + lon2 + "=" + gc(lat1, lon1, lat2, lon2);

    }
    var d2 = new Date();
    var stest = (d2.getTime() - d1.getTime()) / 1000.0 + "s";
    $("#lblTest").html(stest + "<BR/>" + $("#lblTest").html());

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:47:43+00:00Added an answer on May 26, 2026 at 6:47 am

    If you want to execute a long running operation in javascript and you are getting anywhere close to the script execution time limit enforced by some browsers, then you will have to break your function into multiple pieces, run one piece, to a very short setTimeout(fn, 1) and then execute the next piece, etc… Doing it this way, you can run code for hours because it gives other scripts and other events a chance to process. It sometimes requires a minor amount of code restructuring to be able to do this, but it’s always possible with a little work.

    The basic concept in pseudo-code would be this:

    var state = {};   // set initial state
    var done = false;
    
    function doWork() {
       // do one increment of work that will never get even close to the browser
       // execution time limit
       // update the state object with our current operating state for the next execution
       // set done = true when we're done processing
       if (!done) {
           setTimeout(doWork, 1);
       }
    }
    
    doWork();
    

    In your specific code, you could do something like this. You can process 100 latitude points at a time and then do a short setTimeout to do the next 100 and so on. You can adjust that 100 number to whatever would work best. The higher the number, the more you do on each timer and the better overall execution time, but the closer you get to the browser script execution limit. The setTimeout keeps the browser alive (processing other events) and prevents the execution time limit from kicking in.

    function test() {
        var d1 = new Date();
        var lat1, lon1, lat2, lon2, done = false;;
        lat1 = -36;
        lon1 = 174;
    
        lat2 = lat1;
        lon2 = lon1;
    
        function calcGC() {
            var cntr = 0;
            while (lat2 > -37 && cntr < 100) {
                lat2 = lat2 - 0.001;
                var stest = "lat1=" + lat1 + ",lon1=" + lon1 + ",lat2=" + lat2 + ",lon2=" + lon2 + "=" + gc(lat1, lon1, lat2, lon2);
                cntr++;
            }
            // if we have more to go, then call it again on a timeout
            if (lat2 > -37) {
                setTimeout(calcGC, 1);
            } else {
                var d2 = new Date();
                var stest = (d2.getTime() - d1.getTime()) / 1000.0 + "s";
                $("#lblTest").html(stest + "<BR/>" + $("#lblTest").html());
            }
        }
        calcGC();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following test case in my iOS application : -(void) testTwoDefaultUsersExist {
I have a test class that should basically be like the following: [TestClass] public
I have the following thing in my bat file. say set path=c:\temp\test so basically
The following test case passes in .NET 4.0: var fiT = new FileInfo(myhappyfilename); Assert.IsNotNull(fiT);
I have the following test case: @ContextConfiguration(/spring/test-context.xml) @TransactionConfiguration(transactionManager=txManager) @Transactional() public class MyEntityDaoTestCase extends AbstractJUnit4SpringContextTests
For my test I have the following: test should update holder do holder =
I have the following test - public void testStore() throws ItemNotStoredException { Boolean result
After doing the following test: for( i = 0; i < 3000000; i++ )
I have following test.pyx cdef public class Foo[object Foo, type FooType]: cdef public char*
I have a following test @Test public void testPutDocuments() throws Exception { final DBObject

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.