Last active
October 7, 2016 09:34
-
-
Save Spyryto/86150c5836e09db1f06781dcb78a08e9 to your computer and use it in GitHub Desktop.
TalkScript transpiling #jsbench #jsperf (http://jsbench.github.io/#86150c5836e09db1f06781dcb78a08e9) #jsbench #jsperf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"/> | |
<title>TalkScript transpiling #jsbench #jsperf</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script> | |
<script src="./suite.js"></script> | |
</head> | |
<body> | |
<h1>Open the console to view the results</h1> | |
<h2><code>cmd + alt + j</code> or <code>ctrl + alt + j</code></h2> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
(function (factory) { | |
if (typeof Benchmark !== "undefined") { | |
factory(Benchmark); | |
} else { | |
factory(require("benchmark")); | |
} | |
})(function (Benchmark) { | |
var suite = new Benchmark.Suite; | |
Benchmark.prototype.setup = function () { | |
function hereDoc(f) { | |
return f.toString(). | |
replace(/^[^\/]+\/\*!?/, ''). | |
replace(/\*\/[^\/]+$/, ''); | |
} | |
var s = hereDoc(function() {/*! | |
function pageMarkup ( params) { | |
var keepSpyral = false | |
doc = params.doc || document | |
var doctype = [: | |
var publicId = [: ^ dt .publicId ? ' PUBLIC "' + dt .publicId + '"' : '' :] | |
var systemId = [: ^ dt .systemId ? ' "' + dt .systemId + '"' : '' :] | |
var dt = doc .doctype | |
^ [ | |
"<!DOCTYPE ", dt .name, publicId (), systemId (), '>' | |
] .join ( '' ) | |
:] | |
var collectionToArray = [| collection |: | |
^ Array :: slice .call ( collection ) | |
:] | |
var stripSpyralTags = [| node |: | |
var myCopy = node .cloneNode ( true ) | |
var nodes = collectionToArray ( | |
myCopy .getElementsByClassName ( 'spyral' ) | |
) | |
nodes .forEach :| element |: | |
element .remove () | |
]: | |
console .log ( node ) | |
^ myCopy | |
:] | |
var stripTags = [| node, list |: | |
var myCopy = node .cloneNode ( true ) | |
for ( var i = list.length; i-- ;) { | |
var nodes = collectionToArray ( | |
myCopy .getElementsByClassName ( list[i] ) | |
) | |
nodes .forEach :| element |: | |
element .remove () | |
]: | |
} | |
console .log ( node ) | |
^ myCopy | |
:] | |
var htmlElement = [: ^ document .childNodes [1] :] | |
var markup = [| el |: | |
^ stripTags( keepSpyral ? el : stripSpyralTags ( el ), ['firebugResetStyles']) .outerHTML | |
:] | |
^ [ | |
doctype (), | |
"\n", | |
markup ( htmlElement () ), | |
// should we strip off all Spyral scripts and styles? | |
// that is, all elements with class="spyral" | |
// maybe add a boolean flag | |
// keepSpyral: false | |
] .join ( '' ) | |
} | |
function ajaxPageMarkup ( ) { | |
var newDoc = $ ( "html" ) .clone () | |
// replace all tags with source attribute | |
// with php code | |
var ajaxNode = newDoc .find ( "[source]" ) | |
// FIX: the PHP tags get jammed: "<?php" becomes "<!--?php" | |
ajaxNode .each :[ | |
$ ( this ) .html([ | |
'<?php', | |
'include("' + $ ( this ) .attr ( 'source' ) + '");', | |
'?>' | |
] .join ( '\n' )) | |
]: | |
^ "<!DOCTYPE html>\n" + newDoc[0] .outerHTML | |
} | |
function savePage ( doc ) { | |
doc = doc || document | |
var pathName | |
if ( doc. location .pathname .endsWith ( '/' ) ) { | |
pathName = doc. location .pathname + 'index.html' | |
} else { | |
pathName = doc. location .pathname | |
} | |
$ .ajax ({ | |
type : 'POST', | |
url : '/.spyral/save.php', | |
data : { | |
'file' : pathName, | |
'content' : pageMarkup ({ document: doc }) | |
}, | |
success : [| response |: console .log ( response ) :] | |
}) | |
^ false | |
} | |
function savePageToFile ( folder, fileName, doc ) { | |
doc = doc || document | |
^ $ .ajax ({ | |
type : 'POST', | |
url : '/.spyral/makedir-save.php', | |
data : { | |
'file' : fileName, | |
'folder' : folder, | |
'content' : pageMarkup ({ document: doc }) | |
} | |
}) | |
} | |
function saveToFile ( fileName, content, doc ) { | |
doc = doc || document | |
$ .ajax ({ | |
type : 'POST', | |
url : '/.spyral/save.php', | |
data : { | |
'file' : fileName, | |
'content' : content | |
}, | |
success : [| response |: console .log ( response ) :] | |
}) | |
^ false | |
} | |
function appendToFile ( fileName, content ) { | |
^ $ .ajax ({ | |
type : 'POST', | |
url : '/.spyral/append.php', | |
data : { | |
'file' : fileName, | |
'content' : content | |
} | |
}) | |
//return false | |
} | |
// Draggable handle | |
function showHalos ( object ) { | |
// Drag handle | |
$ ( '<div class="drag handle">H</div>' ) | |
.appendTo ( object ) | |
.css({ | |
position : 'absolute' , | |
top : 0 , | |
left : '100%' , | |
border : '1px solid black' , | |
'background-color' : 'yellow' , | |
padding : '0 0.5em' , | |
'border-radius' : '1em' , | |
cursor : 'move' | |
}) | |
object .draggable ({ | |
//handle: ".drag.handle", | |
stop : [| event, ui |: | |
//var fontSize = parseFloat ( $ ( this ) .css ( 'font-size' ) ) | |
var fontSize = parseFloat ( $('html').css('font-size') ) | |
object .css ({ | |
top : ( ui .position .top / fontSize ) + 'rem' , | |
left : ( ui .position .left / fontSize ) + 'rem' | |
}) | |
:] | |
}) | |
//object.draggable(); | |
// "Done" button | |
$ ( '<div class="done handle">Done</div>' ) | |
.appendTo ( object ) | |
.css ({ | |
'position' : 'absolute' , | |
'top' : '2em' , | |
'left' : '100%' , | |
'border' : '1px solid black' , | |
'background-color' : 'yellow' , | |
'padding' : '0 0.5em' , | |
'border-radius' : '1em' , | |
'cursor' : 'default' | |
}) | |
.click :[ object .children ( '.handle' ) .remove () ]: | |
} | |
var editor | |
function openEditor () { | |
if ( editor ) { | |
editor .style .visibility = "visible" | |
console .log ( "Editor visible" ) | |
return | |
} | |
editor = document .createElement ( "div" ) | |
editor .className = "spyral editor" | |
editor .id = "editor" | |
$ ( editor ) .load ( "/.spyral/editor/contents.html" ) | |
document .body .appendChild ( editor ) | |
console .log ( "Editor window created" ) | |
} | |
*/}); | |
function TS_replace (s) { | |
//#Private property | |
s = s.replace("__", "this ._", "g") | |
//#Call to anonymous function with named parameters | |
s = s.replace(":{{", "(function (_args_) { var _sig_ = {", "g") | |
//#Anonymous function with named parameters | |
s = s.replace("{{", "function (_args_) { var _sig_ = {", "g") | |
//#Anonymous function body | |
//# using DSL declaration | |
sub = "}; (function () { var e = arity.process(_args_, _sig_); if (e instanceof TypeError) { console.log(e); throw new TypeError(e.message); } else { _args_ = e .args; _sig_ = e .sig; } })(); for (var _argName_ in _sig_) { if ( _sig_.hasOwnProperty (_argName_) ) { eval ('var ' + _argName_ + ' = _args_.' + _argName_) ; } } " | |
s = s.replace("}:", sub, "g") | |
s = s.replace("):", sub, "g") | |
//# End of anonymous function with named parameters | |
s = s.replace(":}", "; return this ? this : null }", "g") | |
//#End of call to anonymous function with named parameters | |
s = s.replace("}:", "; return this ? this : null })", "g") | |
//#Named function with named parameters | |
s = s.replace("{(", " (_args_) { var _sig_ = {", "g") | |
//#Identifier as name, value | |
s = s.replace(/<<(\w+)>>/, '"$1", $1', "g") | |
//#Identifier as object | |
s = s.replace(/<\{(\w+)\}>/, '{ name: "$1", value: $1 }', "g") | |
//# Anonymous function | |
s = s.replace("[:", "function () {", "g") | |
//# End of anonymous function | |
s = s.replace(":]", "; return this ? this : null }", "g") | |
//# Anonymous function with parameters | |
s = s.replace("[|", "function (", "g") | |
//# End of parameters, Body | |
s = s.replace("|:", ") {", "g") | |
//# Prototype | |
s = s.replace("::", ".prototype.", "g") | |
//# Return | |
s = s.replace("^ ", "return ", "g") | |
//# Call anonymous function | |
s = s.replace(":[", "(function () {", "g") | |
//# End of call to anonymous function | |
s = s.replace("]:", "; return this ? this : null })", "g") | |
//# Call anonymous function with parameters | |
s = s.replace(":|", "(function (", "g") | |
return s | |
} | |
function TS_replace_chaining (s) { | |
var sub = "}; (function () { var e = arity.process(_args_, _sig_); if (e instanceof TypeError) { console.log(e); throw new TypeError(e.message); } else { _args_ = e .args; _sig_ = e .sig; } })(); for (var _argName_ in _sig_) { if ( _sig_.hasOwnProperty (_argName_) ) { eval ('var ' + _argName_ + ' = _args_.' + _argName_) ; } } "; | |
return s | |
//#Private property | |
.replace("__", "this ._", "g") | |
//#Call to anonymous function with named parameters | |
.replace(":{{", "(function (_args_) { var _sig_ = {", "g") | |
//#Anonymous function with named parameters | |
.replace("{{", "function (_args_) { var _sig_ = {", "g") | |
//#Anonymous function body | |
//# using DSL declaration | |
.replace("}:", sub, "g") | |
.replace("):", sub, "g") | |
//# End of anonymous function with named parameters | |
.replace(":}", "; return this ? this : null }", "g") | |
//#End of call to anonymous function with named parameters | |
.replace("}:", "; return this ? this : null })", "g") | |
//#Named function with named parameters | |
.replace("{(", " (_args_) { var _sig_ = {", "g") | |
//#Identifier as name, value | |
.replace(/<<(\w+)>>/, '"$1", $1', "g") | |
//#Identifier as object | |
.replace(/<\{(\w+)\}>/, '{ name: "$1", value: $1 }', "g") | |
//# Anonymous function | |
.replace("[:", "function () {", "g") | |
//# End of anonymous function | |
.replace(":]", "; return this ? this : null }", "g") | |
//# Anonymous function with parameters | |
.replace("[|", "function (", "g") | |
//# End of parameters, Body | |
.replace("|:", ") {", "g") | |
//# Prototype | |
.replace("::", ".prototype.", "g") | |
//# Return | |
.replace("^ ", "return ", "g") | |
//# Call anonymous function | |
.replace(":[", "(function () {", "g") | |
//# End of call to anonymous function | |
.replace("]:", "; return this ? this : null })", "g") | |
//# Call anonymous function with parameters | |
.replace(":|", "(function (", "g") | |
; | |
} | |
function TS_split_join (s) { | |
var sub = "}; (function () { var e = arity.process(_args_, _sig_); if (e instanceof TypeError) { console.log(e); throw new TypeError(e.message); } else { _args_ = e .args; _sig_ = e .sig; } })(); for (var _argName_ in _sig_) { if ( _sig_.hasOwnProperty (_argName_) ) { eval ('var ' + _argName_ + ' = _args_.' + _argName_) ; } } "; | |
//#Private property | |
s = s.split("__").join("this ._") | |
//#Call to anonymous function with named parameters | |
s = s.split(":{{").join("(function (_args_) { var _sig_ = {") | |
//#Anonymous function with named parameters | |
s = s.split("{{").join ("function (_args_) { var _sig_ = {") | |
//#Anonymous function body | |
//# using DSL declaration | |
s = s.split("}:").join(sub) | |
s = s.split("):").join(sub) | |
//# End of anonymous function with named parameters | |
s = s.split(":}").join("; return this ? this : null }") | |
//#End of call to anonymous function with named parameters | |
s = s.split("}:").join("; return this ? this : null })") | |
//#Named function with named parameters | |
s = s.split("{(").join(" (_args_) { var _sig_ = {") | |
//#Identifier as name, value | |
s = s.replace(/<<(\w+)>>/g, '"$1", $1') | |
//#Identifier as object | |
s = s.replace(/<\{(\w+)\}>/g, '{ name: "$1", value: $1 }') | |
//# Anonymous function | |
s = s.split("[:").join("function () {") | |
//# End of anonymous function | |
s = s.split(":]").join("; return this ? this : null }") | |
//# Anonymous function with parameters | |
s = s.split("[|").join("function (") | |
//# End of parameters, Body | |
s = s.split("|:").join(") {") | |
//# Prototype | |
s = s.split("::").join(".prototype.") | |
//# Return | |
s = s.split("^ ").join("return ") | |
//# Call anonymous function | |
s = s.split(":[").join("(function () {") | |
//# End of call to anonymous function | |
s = s.split("]:").join("; return this ? this : null })") | |
//# Call anonymous function with parameters | |
s = s.split(":|").join("(function (") | |
; | |
return s | |
} | |
function TS_split_join_chaining (s) { | |
var sub = "}; (function () { var e = arity.process(_args_, _sig_); if (e instanceof TypeError) { console.log(e); throw new TypeError(e.message); } else { _args_ = e .args; _sig_ = e .sig; } })(); for (var _argName_ in _sig_) { if ( _sig_.hasOwnProperty (_argName_) ) { eval ('var ' + _argName_ + ' = _args_.' + _argName_) ; } } "; | |
return s | |
//#Private property | |
.split("__").join("this ._") | |
//#Call to anonymous function with named parameters | |
.split(":{{").join("(function (_args_) { var _sig_ = {") | |
//#Anonymous function with named parameters | |
.split("{{").join ("function (_args_) { var _sig_ = {") | |
//#Anonymous function body | |
//# using DSL declaration | |
.split("}:").join(sub) | |
.split("):").join(sub) | |
//# End of anonymous function with named parameters | |
.split(":}").join("; return this ? this : null }") | |
//#End of call to anonymous function with named parameters | |
.split("}:").join("; return this ? this : null })") | |
//#Named function with named parameters | |
.split("{(").join(" (_args_) { var _sig_ = {") | |
//#Identifier as name, value | |
.replace(/<<(\w+)>>/g, '"$1", $1') | |
//#Identifier as object | |
.replace(/<\{(\w+)\}>/g, '{ name: "$1", value: $1 }') | |
//# Anonymous function | |
.split("[:").join("function () {") | |
//# End of anonymous function | |
.split(":]").join("; return this ? this : null }") | |
//# Anonymous function with parameters | |
.split("[|").join("function (") | |
//# End of parameters, Body | |
.split("|:").join(") {") | |
//# Prototype | |
.split("::").join(".prototype.") | |
//# Return | |
.split("^ ").join("return ") | |
//# Call anonymous function | |
.split(":[").join("(function () {") | |
//# End of call to anonymous function | |
.split("]:").join("; return this ? this : null })") | |
//# Call anonymous function with parameters | |
.split(":|").join("(function (") | |
; | |
} | |
}; | |
suite.add("TS_replace (s)", function () { | |
TS_replace (s) | |
}); | |
suite.add("TS_split_join (s)", function () { | |
TS_split_join (s) | |
}); | |
suite.add("TS_replace_chaining (s)", function () { | |
TS_replace_chaining (s) | |
}); | |
suite.add("TS_split_join_chaining (s)", function () { | |
TS_split_join_chaining (s) | |
}); | |
suite.on("cycle", function (evt) { | |
console.log(" - " + evt.target); | |
}); | |
suite.on("complete", function (evt) { | |
console.log(new Array(30).join("-")); | |
var results = evt.currentTarget.sort(function (a, b) { | |
return b.hz - a.hz; | |
}); | |
results.forEach(function (item) { | |
console.log((idx + 1) + ". " + item); | |
}); | |
}); | |
console.log("TalkScript transpiling #jsbench #jsperf"); | |
console.log(new Array(30).join("-")); | |
suite.run(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment