Skip to content

Instantly share code, notes, and snippets.

String.prototype.template = function (scopeEval) {
// Andrea Giammarchi - WTFPL License
var
re = /\$\{([\S\s]*?)\}/g,
evaluate = [],
i = 0,
m
;
while (m = re.exec(this)) {
evaluate.push(
var i,n=300000;
var d0=new Date().getTime();
for(i=0;i<n;++i)
"1.5"-0;
alert("-0: "+(new Date().getTime()-d0)+" ms");
var d0=new Date().getTime();
for(i=0;i<n;++i)
+"1.5";
// Sorry. Hack fail :(
// "Speedup" in opera and chrome because bugs in webkit (compile return undefined)
// and opera (invalid regexp object return).
// Giant thanks to @jdalton and @diegoperini
var i,n=20000;
var i=0;
var t="";
for(i=0;i<10000;++i)
t+=" a";
function repeatStringBinary(str, how_many)
{
how_many|=0; // convert to number and round
str+=""; // convert to string
if(how_many<=0 || str.length==0)
return "";
if(how_many==1)
return str;
if(how_many==2)
function repeatString(str, how_many)
{
how_many|=0; // convert to number and round
str+=""; // convert to string
if(how_many<=0 || str.length==0)
return "";
if(how_many==1)
return str;
if(how_many==2)
/**
@fn construct HTMLDocumentFragment or HTMLElement from 'html' string in 'doc'
@param html string that contains html
@param doc owner HTMLDocument for result. Optional
@return HTMLDocumentFragment or HTMLElement depend from 'html'
*/
$jb.DOMNode._fromHTML=null;
if("applyElement" in $h)
{
/* MODIFY PROTOTYPE */
var _fn=function(){};
_fn.prototype.a=1;
var v=new _fn();
alert(v.a === 1); /* true */
alert(v.constructor === _fn); /* true */
/* REPLACE PROTOTYPE */
var i,n=3000, j;
var a=document.getElementsByTagName('li'), m = a.length, v;
for(j = 0 ; j < m ; ++j)
a[j].b = {};
console.time("1");
for(i = 0 ; i < n ; ++i)
for(j = 0 ; j < m ; ++j)
// tnx http://4umi.com/web/javascript/optimize.php for idea, but while(i--) the best :) (except opera :/)
var _fn = function(){};
var i, n=30, j, m = 100000;
console.time("1");
i = n; while(i--)
{
for( j = 0; j < m; j++ ) _fn();
}