Hi all. Im new to JS and would like to note the following case:
Ive run the following test numerous times
ie:
<html>
<body>
<script type="text/javascript">
var s = 0, o = 0;
for (a=0;a<=10;a++)
{
var start = new Date().getTime();
var res = 0;
for (b=0;b<=100000000;b++)
{
res = 512/128;
}
var end = new Date().getTime();
s += end - start;
var start1 = new Date().getTime();
for (c=0;c<=100000000;c++)
{
res = 512>>7;
}
var end1 = new Date().getTime();
o += end1 - start1;
}
document.write(s-o);
</script>
</body>
</html>
and 9 times out of then the shift operation is faster, but never by much (around 5-10%)
My question is this? Does the javascript compiler notice a possible shift operation and if so perform one. If so why the slight performance increase when using a shift operator?
Please note the number (as long as in power of 2's) and the operation (* or /) didnt really make a difference. Shifts were still slightly faster.
Thank you.