High performance timer

JavaScript

if (window.performance.now) {
    console.log("Using high performance timer");
    getTimestamp = function() { return window.performance.now(); };
} else {
    if (window.performance.webkitNow) {
        console.log("Using webkit high performance timer");
        getTimestamp = function() { return window.performance.webkitNow(); };
    } else {
        console.log("Using low performance timer");
        getTimestamp = function() { return new Date().getTime(); };
    }
}

function encode(value) {
  return jQuery('<div/>').text(value).html();
}

function encode2(value) {
  return "<div>"+value+"</div>";
}

var text = "Central City Police forensic scientist Barry Allen's crime lab is struck by lightning. Allen's electrified body is flung into and shatters a cabinet of chemicals, which are both electrified and forced to interact with each other and with his physiology when they come into physical contact with his body. He soon discovers that the accident has changed his body's metabolism and as a result he has gained the ability to move at superhuman speed. Barry Allen has become the Flash.";

var t1 = getTimestamp();
console.log(encode(text));
var t2 = getTimestamp();
console.log("Time delta: " + (t2 - t1)+'ms');

var t3 = getTimestamp();
console.log(encode2(text));
var t4 = getTimestamp();
console.log("Time delta: " + (t3 - t4)+'ms');