Edit in JSFiddle

function add()
{
    for(var i = 0; i < 1000000; i++)
    {
        //some overhead        
    }
    return 12 + 89;
}

window.onload = function()
{
    if("performance" in window)
    {
        if("now" in window.performance || "mozNow" in window.performance || "msNow" in window.performance || "oNow" in window.performance || "webkitNow" in window.performance)
        {
            document.getElementById("result").innerHTML = "Page Performance API supported";
            
            var start_time = performance.now() || performance.mozNow() || performance.msNow() || performance.oNow() || performance.webkitNow();
            add();
            var end_time = performance.now() || performance.mozNow() || performance.msNow() || performance.oNow() || performance.webkitNow();
            document.getElementById("time_taken").innerHTML = "Time taken to add two numbers is : " + (end_time - start_time);
            
            document.getElementBy
        }
        else
        {
             document.getElementById("result").innerHTML = "High Resolution Time API not supported";
        }
    }
    else
    {
        document.getElementById("result").innerHTML = "Page Performance API not supported";
    }
}
<div id="result"></div>
<div id="time_taken"></div>