JavaScript中奇怪的性能行为

JavaScript中奇怪的性能行为,javascript,performance,google-chrome,Javascript,Performance,Google Chrome,我试图评估一些JavaScript运行时行为,但遇到了一个现象。就在这把小提琴里: 它包含一些简单的HTML <label for="loopCount">Test loops: </label> <input id="loopCount" type="text" value="10000000" /> <input id="testbutton" type="button" value="Run Test" /> <p id="result

我试图评估一些JavaScript运行时行为,但遇到了一个现象。就在这把小提琴里:

它包含一些简单的HTML

<label for="loopCount">Test loops: </label>
<input id="loopCount" type="text" value="10000000" />
<input id="testbutton" type="button" value="Run Test" />
<p id="result">Choose Loop Count and click Run Test</p>
测试循环:

选择循环计数并单击运行测试

还有一点JavaScript用于我的测试。我定义了一个构造函数来创建一些getter/setter属性,因为这正是我想要测试的。对于测量,我在我的测试按钮的点击事件上挂起一个函数,显示“Running”,让浏览器有机会显示它,并继续一个简单的时间测量循环

var MyClass = function() {
    var aValue = 3;
    //var sym = Symbol();    // Uncomment this to get BETTER TIMING. WTF?
    //this[sym] = 123;
    Object.defineProperties(this, {
       myVal: { get: function() { return aValue; },
                set: function(v) { aValue = v; } },
       aCalc: { get: function() { return 2+3*aValue; } } } ); 
    };     

document.getElementById('testbutton').addEventListener('click', function() {
  document.getElementById('result').innerText = "Running...";
  setTimeout(function() {
    var loopCount = parseInt(document.getElementById('loopCount').value);
    var startTime = new Date(),
          endTime,
          i, j = 0,
          c = new MyClass();

      for (i = 0; i < loopCount; i++) {
        j++;
        if (c.aCalc != 11) alert('Wrong at ' + j);
      }
      endTime = new Date();   
    document.getElementById('result').innerText = 'Done, time was ' + (endTime-startTime) + ' ms, j='+  j;
  }, 0);
});
var MyClass=function(){
var aValue=3;
//var sym=Symbol();//取消对此的注释以获得更好的计时。WTF?
//这个[sym]=123;
对象。定义属性(此{
myVal:{get:function(){return aValue;},
set:function(v){aValue=v;}},
aCalc:{get:function(){return 2+3*aValue;}}});
};     
document.getElementById('testbutton')。addEventListener('click',function(){
document.getElementById('result').innerText=“Running…”;
setTimeout(函数(){
var loopCount=parseInt(document.getElementById('loopCount').value);
var startTime=新日期(),
(完),
i、 j=0,
c=新的MyClass();
对于(i=0;i