You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Is it possible you have some other interval or setWatch running in the background that could be keeping it really busy? Maybe try a reset(1) to be sure?

    From a board I just tried:

    >for(var i = 0; i < 10; i++) {var dt = new Date();setTimeout(function(){console.log­(new Date() - dt);},1000);}
    =undefined
    992.88940429687
    994.90356445312
    996.18530273437
    997.86376953125
    999.1455078125
    1000.42724609375
    1002.01416015625
    1003.44848632812
    1004.73022460937
    1010.58959960937
    
    >var dt = new Date();setTimeout(function(){console.log­(new Date() - dt);},100);
    =1
    101.13525390625
    >var dt = new Date();setTimeout(function(){console.log­(new Date() - dt);},100);
    =1
    101.25732421875
    >var dt = new Date();setTimeout(function(){console.log­(new Date() - dt);},100);
    =1
    101.13525390625
    >var dt = new Date();setTimeout(function(){console.log­(new Date() - dt);},100);
    =1
    101.13525390625
    >var dt = new Date();setTimeout(function(){console.log­(new Date() - dt);},100);
    =1
    101.13525390625
    
    
    >function tst(duration){
    :  var pnt = 0;
    :  function tstTimeout(){
    :    var dt = new Date();
    :    setTimeout(function(){
    :      console.log(new Date() - dt);
    :      if(pnt++ < 4) tstTimeout();
    :    },duration);
    :  }
    :  clearTimeout();
    :  tstTimeout();
    :}
    =function (duration) { ... }
    >tst(1000);
    =undefined
    1001.55639648437
    1001.67846679687
    1001.52587890625
    1001.52587890625
    1001.46484375
    

    So all that looks pretty good. You'd expect the ~1ms delay because of the time taken to parse and execute setTimeout after the initial Date variable is created.

About

Avatar for Gordon @Gordon started