My processor runs at 2.0 GHz.
I have a new computer with as much software removed as possible except my development tools. This system is clean with no malware.
When I run the code below I get about 2M loops per second. That is about 1 MHz.
Suppose doing and addition, and doing a compare takes 10x the simplest operation, I get about 10 MHz
Why do I not get more utilization of my processor?
var Utility =
{
time: function()
{
var end_time,
start_time,
index = 0;
start_time = new Date().getTime();
while ( index <= 1000000 )
{
index++;
}
end_time = new Date().getTime();
return ( end_time - start_time);
}
};
This is not really about JavaScript – it’s more about the browser and the way it’s handling JavaScript.
Each browser is doing this differently, but most modern browsers won’t let JavaScript take 100% of the resources to prevent the client machine from crashing.
Bottom line you can’t do such thing with client side scripting, you’ll have to use “real” application with full access to the computer.