Benchmark

A quick and dirty simple calculation benchmark test

by fordcars

HTML

<center>
    <p id="outputId">Output</p>
    <button id="buttonId">Test</button>
</center>

JavaScript

var output = document.getElementById("outputId");
var button = document.getElementById("buttonId");

var iterations = 100000000; // 100000000

var computers = [[5000, "an old pile of junk."], [2000, "a dated computer, or a cheap smartphone."], [1500, "a *normal* computer."], [1000, "a pretty fast computer dude."], [500, "a fast computer."], [250, "a bloody fast computer."], [150, "a freaking fast computer."], [100, "a supercomputer."], [50, "the fastest computer on earth."], [0, "cheated, or have a magically fast computer."]]; // Must be in order!

button.addEventListener("click", clickedButton, false);

function clickedButton()
{
    benchmark();
}

function benchmark()
{
    var value = 1;
    var msBefore = new Date().getTime();
    var msAfter = 0;
    
    for(i=0; i<iterations; i++)
    {
        value = Math.sqrt((value + i)/Math.PI);
    }
    
    msAfter = new Date().getTime();
    analyseOutput(msAfter-msBefore);
}

function analyseOutput(msPassed)
{
    var tempString;
    var computerName = "";
    
    for(i=0, length=computers.length; i<length; i++)
    {
        if(msPassed>computers[i][0])
        {
            computerName = computers[i][1];
            break;
        }
    }
    
    tempString = "You have " + computerName + " (" + msPassed + " ms)";
    output.innerHTML = tempString;
}