📜 ⬆️ ⬇️

Firefox vs Chrome: JS Run Feature

The same simple JS code that does not access the DOM runs at almost the same speed if it is designed as a function in both FireFox (3.1b2) and Chrome (1.0.154.43).
If you put it just in the script tag, then the runtime in Chrome is increased by about 15 times (from 10ms to 150ms)

The code is as follows:

<script>

/*function tst1(){*/

var date1 = new Date();
var milliseconds1 = date1.getTime();

for ( var z = 0; z < 30000; z++) {

if (z % 333 == 0) { for ( var j = 0; j < 30000; j++) ; }
}

var date2 = new Date();
var milliseconds2 = date2.getTime();

var difference = milliseconds2 - milliseconds1;
alert( "difference == " + difference);

/*}

tst1();*/

</script>


* This source code was highlighted with Source Code Highlighter .

')

Source: https://habr.com/ru/post/53072/


All Articles