User:SG/NavFrame test

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">   // <![CDATA[ function testFunction (n, f) { var start = new Date; for (var i = 0; i < n; i++) { f; } return new Date.getTime - start.getTime; }

function compareAll (n, funcs) { var fns = new Array; var times = {};

document.write(""); for (var fn in funcs) { var f = funcs[fn]; if (f) { var t = testFunction(n, f); fns.push(fn); times[fn] = t;			document.write("" + fn + " x " + n + ": " + t + " ms"); }	}	document.write("");

fns.sort(function (a, b) { return times[b] - times[a]; });

document.write(" "); } //]]>

 // <![CDATA[ var hasClass1 = (function {	var reCache1 = {};	function getRegex(className) {		if (reCache1[className]) return reCache1[className];

var re = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"); reCache1[className] = re; return re; }

return function (element, className) { return element.className.match(getRegex(className)); }; });

function hasClass2 (element, className) { return element.className.match(		new RegExp("(?:\\s|^)" + className + "(?:\\s|$)")); }

function hasClass3 (element, className) { var Classes = element.className.split( " " ); for ( var i = 0; i < Classes.length; i++ ) { if ( Classes[i] == className ) { return ( true ); } }  return ( false ); }

var hasClass4 = (function {	var reCache2 = {};	return function (element, className) {		var re = reCache2[className];		if (!re) {			re = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)");			reCache2[className] = re;		}

return element.className.match(re); }; });

function hasClass5 (element, className) { return element.className.match(		new RegExp("(\\s|^)" + className + "(\\s|$)")); }

var hasClass9 = (function {	var reCache6 = {};	return function (element, className) {		return (reCache6[className] ? reCache6[className] : (reCache6[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);	}; });

var test = document.getElementById("test");

compareAll(10000, {	"re+cache": function { hasClass1(test, String.fromCharCode(97 + Math.round(Math.random * 25))) },	"re+nocache": function  { hasClass2(test, String.fromCharCode(97 + Math.round(Math.random * 25))) },	"split": function  { hasClass3(test, String.fromCharCode(97 + Math.round(Math.random * 25))) },	"re+nocache+capture": function  { hasClass5(test, String.fromCharCode(97 + Math.round(Math.random * 25))) },	//"re+literal": function  { test.className.match(/(?:^|\s)d(?:$|\s)/) },	"re+cache+onefunc4": function  { hasClass4(test, String.fromCharCode(97 + Math.round(Math.random * 25))) },	"re+cache+onefunc9": function  { hasClass9(test, String.fromCharCode(97 + Math.round(Math.random * 25))) } }); //]]>