Note that there are some explanatory texts on larger screens.

plurals
  1. POchrome profiler producing seemingly random results
    primarykey
    data
    text
    <p>I am trying to determine which of three ways of calculating something is fastest. To determine this I simply loop a large number of times calling each and expect to look in the profiler to see how long each took.</p> <p>Profiling with both firefox + firebug and IE 9 developer tools gives reasonable results, showing how much time was spent in each function. In Google Chrome though, I never see all three functions in the profile results, and worse, it shows different functions each time, but never all three. I continue to get different looking results each time I run the profiler.</p> <p>I'm assuming the profiler works and I just don't know how to use it, but this sure seems broken to me. I dont see anything to explain this behavior in the <a href="https://developers.google.com/chrome-developer-tools/docs/cpu-profiling" rel="nofollow noreferrer">docs</a>. (I was using normal release but also tried developer release (Version 26.0.1410.10 dev-m) to see if it worked better - it didn't. Increasing the number of times the loop is run, didn't seem to help either)</p> <p>Sample Firebug results (shows the 3 functions + run and onClick as expected): <img src="https://i.stack.imgur.com/c8Jnh.png" alt="enter image description here"></p> <p>Sample Chrome results #1 (shows only 1 of the 3): <img src="https://i.stack.imgur.com/PNRJU.png" alt="Chrome profiler results #1"></p> <p>Sample Chrome results #2 (shows 2 of the 3): <img src="https://i.stack.imgur.com/lQJ7g.png" alt="Chrome profiler results #2"></p> <p>The code being profiled is: </p> <pre><code>&lt;html lang="en" xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta charset="utf-8" /&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;button onclick="run()"&gt;Run Test&lt;/button&gt; &lt;script type="text/javascript"&gt; var R = 6371, toRad = Math.PI / 180; function haversine1(lat1, lon1, lat2, lon2) { var dLat = (lat2 - lat1) * toRad, dLon = (lon2 - lon1) * toRad, 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), c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return (R * c); } function haversine2(lat1, lon1, lat2, lon2) { lat1 = lat1 * toRad; lon1 = lon1 * toRad; lat2 = lat2 * toRad; lon2 = lon2 * toRad; var dLat = lat2 - lat1, dLon = lon2 - lon1, a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(lat1) * Math.cos(lat2) * Math.sin(dLon / 2) * Math.sin(dLon / 2), c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return (R * c); } function lawOfCosines(lat1, lon1, lat2, lon2) { lat1 = lat1 * toRad; lon1 = lon1 * toRad; lat2 = lat2 * toRad; lon2 = lon2 * toRad; return Math.acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1)) * R; } function run() { console.log('Test start'); var lat1 = 90, lat2 = -90, lon1 = 180, lon2 = -180, i = 0, x, y, z while (i++ &lt; 1000000) { lat1 -= .01; lat2 += .01; lon1 -= .01; lon2 += .01; if (lat1 &lt; -90) lat1 = 90; if (lat2 &gt; 90) lat2 = -90; if (lon1 &lt; -180) lon1 = 180; if (lon2 &gt; 180) lon2 = -180; x = haversine1(lat1, lon1, lat2, lon2); y = haversine2(lat1, lon1, lat2, lon2); z = lawOfCosines(lat1, lon1, lat2, lon2); if (i % 1000 === 0) { console.log('x: ' + x + ' y: ' + y + ' z: ' + z); } } console.log('Test end'); } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload