Skip to content

Instantly share code, notes, and snippets.

@mattmccray
Created October 19, 2012 04:15
Show Gist options
  • Star 26 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save mattmccray/3916195 to your computer and use it in GitHub Desktop.
Save mattmccray/3916195 to your computer and use it in GitHub Desktop.
Simple comparison of several compile-to-javascript languages, including: CoffeeScript, Dart, Haxe, and TypeScript.
/usr/bin/time dart2js -ooutput/dart.js source/simple.dart
3.30 real 3.01 user 0.25 sys
/usr/bin/time tsc --out output/typescript.js --sourcemap source/simple.ts
0.98 real 0.86 user 0.10 sys
/usr/bin/time coffee -p source/simple.coffee > output/coffee.js
0.18 real 0.14 user 0.02 sys
/usr/bin/time haxe -cp source/ -main Simple -js output/haxe.js --dead-code-elimination --js-modern -debug
0.05 real 0.04 user 0.01 sys
/usr/bin/time jsx --executable web --enable-source-map --output output/jsx.js source/simple.jsx
0.42 real 0.35 user 0.05 sys
(function() {
var Simple;
Simple = (function() {
function Simple(name) {
this.name = name != null ? name : "default";
}
Simple.prototype.greet = function(who) {
return "Greetings " + who + ", I'm " + this.name + "!";
};
Simple.main = function() {
var s;
s = new Simple("Flynn");
return console.log(s.greet("Program"));
};
return Simple;
})();
Simple.main();
}).call(this);
// Generated by dart2js, the Dart to JavaScript compiler.
// The code supports the following hooks:
// dartPrint(message) - if this function is defined it is called
// instead of the Dart [print] method.
// dartMainRunner(main) - if this function is defined, the Dart [main]
// method will not be invoked directly.
// Instead, a closure that will invoke [main] is
// passed to [dartMainRunner].
function Isolate() {}
init();
var $$ = {};
var $ = Isolate.$isolateProperties;
$$.StringBufferImpl = {"":
["_buffer", "_length"],
"super": "Object",
get$length: function() {
return this._length;
},
isEmpty$0: function() {
return this._length === 0;
},
add$1: function(obj) {
var str = $.toString(obj);
if (str == null || $.isEmpty(str) === true)
return this;
$.add$1(this._buffer, str);
this._length = $.add(this._length, $.get$length(str));
return this;
},
clear$0: function() {
this._buffer = $.ListImplementation_List(null);
this._length = 0;
return this;
},
toString$0: function() {
if ($.get$length(this._buffer) === 0)
return '';
if ($.get$length(this._buffer) === 1)
return $.index(this._buffer, 0);
var result = $.StringImplementation_concatAll(this._buffer);
$.clear(this._buffer);
$.add$1(this._buffer, result);
return result;
},
StringBufferImpl$1: function(content$) {
this.clear$0();
this.add$1(content$);
}
};
$$.ArgumentError = {"":
["message"],
"super": "Object",
toString$0: function() {
var t1 = this.message;
if (!(t1 == null))
return 'Illegal argument(s): ' + $.S(t1);
return 'Illegal argument(s)';
}
};
$$.IndexOutOfRangeException = {"":
["_value"],
"super": "Object",
toString$0: function() {
return 'IndexOutOfRangeException: ' + $.S(this._value);
}
};
$$.NullPointerException = {"":
["functionName", "arguments"],
"super": "Object",
toString$0: function() {
var t1 = this.functionName;
if (t1 == null)
return this.get$exceptionName();
else
return $.S(this.get$exceptionName()) + ' : method: \'' + $.S(t1) + '\'\n' + 'Receiver: null\n' + 'Arguments: ' + $.S(this.arguments);
},
get$exceptionName: function() {
return 'NullPointerException';
}
};
$$.NoMoreElementsException = {"":
[],
"super": "Object",
toString$0: function() {
return 'NoMoreElementsException';
}
};
$$.UnsupportedOperationException = {"":
["_message"],
"super": "Object",
toString$0: function() {
return 'UnsupportedOperationException: ' + this._message;
}
};
$$.Object = {"":
[],
"super": "",
operator$eq$1: function(other) {
return this === other;
},
toString$0: function() {
return $.Primitives_objectToString(this);
}
};
$$.ListIterator = {"":
["i", "list"],
"super": "Object",
hasNext$0: function() {
return this.i < this.list.length;
},
next$0: function() {
if (this.hasNext$0() !== true)
throw $.$$throw($.NoMoreElementsException$());
var value = this.list[this.i];
this.i = this.i + 1;
return value;
}
};
$$.Closure = {"":
[],
"super": "Object",
toString$0: function() {
return 'Closure';
}
};
$$.Simple = {"":
["name"],
"super": "Object",
greet$1: function(who) {
return 'Greetings ' + who + ', I\'m ' + this.name + '!';
}
};
$$.Maps__emitMap_anon = {"":
["result_3", "box_0", "visiting_2"],
"super": "Closure",
call$2: function(k, v) {
var t1 = this.box_0;
if (t1.first_1 !== true)
$.add$1(this.result_3, ', ');
t1.first_1 = false;
t1 = this.result_3;
var t2 = this.visiting_2;
$.Collections__emitObject(k, t1, t2);
$.add$1(t1, ': ');
$.Collections__emitObject(v, t1, t2);
}
};
$.S = function(value) {
var res = $.toString(value);
if (!(typeof res === 'string'))
throw $.$$throw($.ArgumentError$(value));
return res;
};
$.StringBuffer_StringBuffer = function(content$) {
return $.StringBufferImpl$(content$);
};
$.gt$slow = function(a, b) {
if ($.checkNumbers(a, b))
return a > b;
return a.operator$gt$1(b);
};
$.checkGrowable = function(list, reason) {
if (!!(list.fixed$length))
throw $.$$throw($.UnsupportedOperationException$(reason));
};
$.$$throw = function(ex) {
if (ex == null)
ex = $.CTC;
var jsError = new Error();
jsError.name = ex;
jsError.description = ex;
jsError.dartException = ex;
jsError.toString = $.toStringWrapper.call$0;
throw jsError;
};
$.iterator = function(receiver) {
if ($.isJsArray(receiver))
return $.ListIterator$(receiver);
return receiver.iterator$0();
};
$.ArgumentError$ = function(message) {
return new $.ArgumentError(message);
};
$.NullPointerException$ = function(functionName, arguments$) {
return new $.NullPointerException(functionName, arguments$);
};
$.eqB = function(a, b) {
if (a == null)
return b == null;
if (b == null)
return false;
if (typeof a === "object")
if (!!a.operator$eq$1)
return a.operator$eq$1(b) === true;
return a === b;
};
$.add$1 = function(receiver, value) {
if ($.isJsArray(receiver)) {
$.checkGrowable(receiver, 'add');
receiver.push(value);
return;
}
return receiver.add$1(value);
};
$.Collections__emitCollection = function(c, result, visiting) {
$.add$1(visiting, c);
var isList = typeof c === 'object' && c !== null && (c.constructor === Array || !!c.is$List);
$.add$1(result, isList ? '[' : '{');
for (var t1 = $.iterator(c), first = true; t1.hasNext$0() === true;) {
var t2 = t1.next$0();
if (!first)
$.add$1(result, ', ');
$.Collections__emitObject(t2, result, visiting);
first = false;
}
$.add$1(result, isList ? ']' : '}');
$.removeLast(visiting);
};
$.Primitives_newList = function(length$) {
if (length$ == null)
return new Array();
if (!(typeof length$ === 'number' && Math.floor(length$) === length$) || length$ < 0)
throw $.$$throw($.ArgumentError$(length$));
var result = new Array(length$);
result.fixed$length = true;
return result;
};
$.set$length = function(receiver, newLength) {
if ($.isJsArray(receiver)) {
$.checkNull(newLength);
if (newLength < 0)
throw $.$$throw($.IndexOutOfRangeException$(newLength));
$.checkGrowable(receiver, 'set length');
receiver.length = newLength;
} else
receiver.set$length(newLength);
return newLength;
};
$.Primitives_printString = function(string) {
if (typeof dartPrint == "function") {
dartPrint(string);
return;
}
if (typeof window == "object") {
if (typeof console == "object")
console.log(string);
return;
}
if (typeof print == "function") {
print(string);
return;
}
throw 'Unable to print message: ' + String(string);
};
$.toStringWrapper = function() {
return $.toString(this.dartException);
};
$.checkNum = function(value) {
if (!(typeof value === 'number')) {
$.checkNull(value);
throw $.$$throw($.ArgumentError$(value));
}
return value;
};
$.get$length = function(receiver) {
if (typeof receiver === 'string' || $.isJsArray(receiver))
return receiver.length;
else
return receiver.get$length();
};
$.constructorNameFallback = function(object) {
var constructor$ = object.constructor;
if (typeof(constructor$) === 'function') {
var name$ = constructor$.name;
if (typeof name$ === 'string')
var t1 = !(name$ === '') && !(name$ === 'Object') && !(name$ === 'Function.prototype');
else
t1 = false;
if (t1)
return name$;
}
var string = Object.prototype.toString.call(object);
return string.substring(8, string.length - 1);
};
$.toString = function(value) {
if (typeof value == "object" && value !== null)
if ($.isJsArray(value))
return $.Collections_collectionToString(value);
else
return value.toString$0();
if (value === 0 && (1 / value) < 0)
return '-0.0';
if (value == null)
return 'null';
if (typeof value == "function")
return 'Closure';
return String(value);
};
$.IndexOutOfRangeException$ = function(_value) {
return new $.IndexOutOfRangeException(_value);
};
$.index = function(a, index) {
if (typeof a == "string" || a.constructor === Array) {
var key = index >>> 0;
if (key === index && key < a.length)
return a[key];
}
return $.index$slow(a, index);
};
$.substring$2 = function(receiver, startIndex, endIndex) {
$.checkNum(startIndex);
var length$ = receiver.length;
if (endIndex == null)
endIndex = length$;
$.checkNum(endIndex);
if (startIndex < 0)
throw $.$$throw($.IndexOutOfRangeException$(startIndex));
if ($.gtB(startIndex, endIndex))
throw $.$$throw($.IndexOutOfRangeException$(startIndex));
if ($.gtB(endIndex, length$))
throw $.$$throw($.IndexOutOfRangeException$(endIndex));
return $.substringUnchecked(receiver, startIndex, endIndex);
};
$.StringBufferImpl$ = function(content$) {
var t1 = new $.StringBufferImpl(null, null);
t1.StringBufferImpl$1(content$);
return t1;
};
$.UnsupportedOperationException$ = function(_message) {
return new $.UnsupportedOperationException(_message);
};
$.removeLast = function(receiver) {
if ($.isJsArray(receiver)) {
$.checkGrowable(receiver, 'removeLast');
if ($.get$length(receiver) === 0)
throw $.$$throw($.IndexOutOfRangeException$(-1));
return receiver.pop();
}
return receiver.removeLast$0();
};
$.gtB = function(a, b) {
return typeof a === 'number' && typeof b === 'number' ? a > b : $.gt$slow(a, b) === true;
};
$.Simple$ = function(name$) {
return new $.Simple(name$);
};
$.ltB = function(a, b) {
return typeof a === 'number' && typeof b === 'number' ? a < b : $.lt$slow(a, b) === true;
};
$.isJsArray = function(value) {
return !(value == null) && value.constructor === Array;
};
$.StringImplementation_concatAll = function(strings) {
return $.stringJoinUnchecked($.StringImplementation__toJsStringArray(strings), '');
};
$.substring$1 = function(receiver, startIndex) {
if (!(typeof receiver === 'string'))
return receiver.substring$1(startIndex);
return $.substring$2(receiver, startIndex, null);
};
$.clear = function(receiver) {
if (!$.isJsArray(receiver))
return receiver.clear$0();
$.set$length(receiver, 0);
};
$.checkNull = function(object) {
if (object == null)
throw $.$$throw($.NullPointerException$(null, $.CTC0));
return object;
};
$.charCodeAt = function(receiver, index) {
if (typeof receiver === 'string') {
if (index < 0)
throw $.$$throw($.IndexOutOfRangeException$(index));
if (index >= receiver.length)
throw $.$$throw($.IndexOutOfRangeException$(index));
return receiver.charCodeAt(index);
} else
return receiver.charCodeAt$1(index);
};
$.Primitives_objectToString = function(object) {
return 'Instance of \'' + $.S($.Primitives_objectTypeName(object)) + '\'';
};
$.Primitives_objectTypeName = function(object) {
var name$ = $.constructorNameFallback(object);
if ($.eqB(name$, 'Object')) {
var decompiled = String(object.constructor).match(/^\s*function\s*(\S*)\s*\(/)[1];
if (typeof decompiled === 'string')
name$ = decompiled;
}
return $.charCodeAt(name$, 0) === 36 ? $.substring$1(name$, 1) : name$;
};
$.lt$slow = function(a, b) {
if ($.checkNumbers(a, b))
return a < b;
return a.operator$lt$1(b);
};
$.Collections__emitObject = function(o, result, visiting) {
if (typeof o === 'object' && o !== null && (o.constructor === Array || !!o.is$Collection))
if ($.Collections__containsRef(visiting, o))
$.add$1(result, typeof o === 'object' && o !== null && (o.constructor === Array || !!o.is$List) ? '[...]' : '{...}');
else
$.Collections__emitCollection(o, result, visiting);
else if (typeof o === 'object' && o !== null && !!o.is$Map)
if ($.Collections__containsRef(visiting, o))
$.add$1(result, '{...}');
else
$.Maps__emitMap(o, result, visiting);
else
$.add$1(result, o);
};
$.Maps__emitMap = function(m, result, visiting) {
var t1 = {};
$.add$1(visiting, m);
$.add$1(result, '{');
t1.first_1 = true;
m.forEach$1(new $.Maps__emitMap_anon(result, t1, visiting));
$.add$1(result, '}');
$.removeLast(visiting);
};
$.checkNumbers = function(a, b) {
if (typeof a === 'number')
if (typeof b === 'number')
return true;
else {
$.checkNull(b);
throw $.$$throw($.ArgumentError$(b));
}
return false;
};
$.main = function() {
$.print($.Simple$('Flyn').greet$1('Program'));
};
$.StringImplementation__toJsStringArray = function(strings) {
if (typeof strings !== 'object' || strings === null || (strings.constructor !== Array || !!strings.immutable$list) && !strings.is$JavaScriptIndexingBehavior)
return $.StringImplementation__toJsStringArray$bailout(1, strings);
$.checkNull(strings);
var length$ = strings.length;
if ($.isJsArray(strings)) {
for (var i = 0; i < length$; ++i) {
if (i >= strings.length)
throw $.ioore(i);
var string = strings[i];
$.checkNull(string);
if (!(typeof string === 'string'))
throw $.$$throw($.ArgumentError$(string));
}
var array = strings;
} else {
array = $.ListImplementation_List(length$);
for (i = 0; i < length$; ++i) {
if (i >= strings.length)
throw $.ioore(i);
string = strings[i];
$.checkNull(string);
if (!(typeof string === 'string'))
throw $.$$throw($.ArgumentError$(string));
array[i] = string;
}
}
return array;
};
$.ListImplementation_List = function(length$) {
return $.Primitives_newList(length$);
};
$.index$slow = function(a, index) {
if (typeof a === 'string' || $.isJsArray(a)) {
if (!(typeof index === 'number' && Math.floor(index) === index)) {
if (!(typeof index === 'number'))
throw $.$$throw($.ArgumentError$(index));
if (!($.truncate(index) === index))
throw $.$$throw($.ArgumentError$(index));
}
if ($.ltB(index, 0) || $.geB(index, $.get$length(a)))
throw $.$$throw($.IndexOutOfRangeException$(index));
return a[index];
}
return a.operator$index$1(index);
};
$.add = function(a, b) {
return typeof a === 'number' && typeof b === 'number' ? a + b : $.add$slow(a, b);
};
$.truncate = function(receiver) {
return receiver < 0 ? $.ceil(receiver) : $.floor(receiver);
};
$.print = function(object) {
if (typeof object === 'string')
$.Primitives_printString(object);
else
$.Primitives_printString($.toString(object));
};
$.ceil = function(receiver) {
return Math.ceil(receiver);
};
$.ListIterator$ = function(list) {
return new $.ListIterator(0, list);
};
$.Collections__containsRef = function(c, ref) {
for (var t1 = $.iterator(c); t1.hasNext$0() === true;) {
var t2 = t1.next$0();
if (t2 == null ? ref == null : t2 === ref)
return true;
}
return false;
};
$.Collections_collectionToString = function(c) {
var result = $.StringBuffer_StringBuffer('');
$.Collections__emitCollection(c, result, $.ListImplementation_List(null));
return $.toString(result);
};
$.NoMoreElementsException$ = function() {
return new $.NoMoreElementsException();
};
$.isEmpty = function(receiver) {
if (typeof receiver === 'string' || $.isJsArray(receiver))
return receiver.length === 0;
return receiver.isEmpty$0();
};
$.stringJoinUnchecked = function(array, separator) {
return array.join(separator);
};
$.geB = function(a, b) {
return typeof a === 'number' && typeof b === 'number' ? a >= b : $.ge$slow(a, b) === true;
};
$.ge$slow = function(a, b) {
if ($.checkNumbers(a, b))
return a >= b;
return a.operator$ge$1(b);
};
$.substringUnchecked = function(receiver, startIndex, endIndex) {
return receiver.substring(startIndex, endIndex);
};
$.ioore = function(index) {
throw $.$$throw($.IndexOutOfRangeException$(index));
};
$.floor = function(receiver) {
return Math.floor(receiver);
};
$.add$slow = function(a, b) {
if ($.checkNumbers(a, b))
return a + b;
return a.operator$add$1(b);
};
$.StringImplementation__toJsStringArray$bailout = function(state0, strings) {
$.checkNull(strings);
var length$ = $.get$length(strings);
if ($.isJsArray(strings)) {
for (var i = 0; $.ltB(i, length$); ++i) {
var string = $.index(strings, i);
$.checkNull(string);
if (!(typeof string === 'string'))
throw $.$$throw($.ArgumentError$(string));
}
var array = strings;
} else {
array = $.ListImplementation_List(length$);
for (i = 0; $.ltB(i, length$); ++i) {
string = $.index(strings, i);
$.checkNull(string);
if (!(typeof string === 'string'))
throw $.$$throw($.ArgumentError$(string));
if (i >= array.length)
throw $.ioore(i);
array[i] = string;
}
}
return array;
};
$.toStringWrapper.call$0 = $.toStringWrapper;
$.toStringWrapper.$name = "toStringWrapper";
Isolate.$finishClasses($$);
$$ = {};
Isolate.makeConstantList = function(list) {
list.immutable$list = true;
list.fixed$length = true;
return list;
};
$.CTC0 = Isolate.makeConstantList([]);
$.CTC1 = null;
$.CTC = new Isolate.$isolateProperties.NullPointerException(null, Isolate.$isolateProperties.CTC0);
$.Primitives_DOLLAR_CHAR_VALUE = 36;
var $ = null;
Isolate.$finishClasses($$);
$$ = {};
Isolate = Isolate.$finishIsolateConstructor(Isolate);
var $ = new Isolate();
//
// BEGIN invoke [main].
//
if (typeof document != 'undefined' && document.readyState != 'complete') {
document.addEventListener('readystatechange', function () {
if (document.readyState == 'complete') {
if (typeof dartMainRunner == 'function') {
dartMainRunner(function() { $.main(); });
} else {
$.main();
}
}
}, false);
} else {
if (typeof dartMainRunner == 'function') {
dartMainRunner(function() { $.main(); });
} else {
$.main();
}
}
//
// END invoke [main].
//
function init() {
Isolate.$isolateProperties = {};
Isolate.$defineClass = function(cls, fields, prototype) {
var generateGetterSetter = function(field, prototype) {
var len = field.length;
var lastChar = field[len - 1];
var needsGetter = lastChar == '?' || lastChar == '=';
var needsSetter = lastChar == '!' || lastChar == '=';
if (needsGetter || needsSetter) field = field.substring(0, len - 1);
if (needsGetter) {
var getterString = "return this." + field + ";";
prototype["get$" + field] = new Function(getterString);
}
if (needsSetter) {
var setterString = "this." + field + " = v;";
prototype["set$" + field] = new Function("v", setterString);
}
return field;
};
var constructor;
if (typeof fields == 'function') {
constructor = fields;
} else {
var str = "function " + cls + "(";
var body = "";
for (var i = 0; i < fields.length; i++) {
if (i != 0) str += ", ";
var field = fields[i];
field = generateGetterSetter(field, prototype);
str += field;
body += "this." + field + " = " + field + ";\n";
}
str += ") {" + body + "}\n";
str += "return " + cls + ";";
constructor = new Function(str)();
}
constructor.prototype = prototype;
return constructor;
};
var supportsProto = false;
var tmp = Isolate.$defineClass('c', ['f?'], {}).prototype;
if (tmp.__proto__) {
tmp.__proto__ = {};
if (typeof tmp.get$f !== "undefined") supportsProto = true;
}
Isolate.$pendingClasses = {};
Isolate.$finishClasses = function(collectedClasses) {
var hasOwnProperty = Object.prototype.hasOwnProperty;
for (var cls in collectedClasses) {
if (hasOwnProperty.call(collectedClasses, cls)) {
var desc = collectedClasses[cls];
Isolate.$isolateProperties[cls] = Isolate.$defineClass(cls, desc[''], desc);
if (desc['super'] !== "") Isolate.$pendingClasses[cls] = desc['super'];
}
}
var pendingClasses = Isolate.$pendingClasses;
Isolate.$pendingClasses = {};
var finishedClasses = {};
function finishClass(cls) {
var hasOwnProperty = Object.prototype.hasOwnProperty;
if (hasOwnProperty.call(finishedClasses, cls)) return;
finishedClasses[cls] = true;
var superclass = pendingClasses[cls];
if (!superclass) return;
finishClass(superclass);
var constructor = Isolate.$isolateProperties[cls];
var superConstructor = Isolate.$isolateProperties[superclass];
var prototype = constructor.prototype;
if (supportsProto) {
prototype.__proto__ = superConstructor.prototype;
prototype.constructor = constructor;
} else {
function tmp() {};
tmp.prototype = superConstructor.prototype;
var newPrototype = new tmp();
constructor.prototype = newPrototype;
newPrototype.constructor = constructor;
for (var member in prototype) {
if (member == '' || member == 'super') continue;
if (hasOwnProperty.call(prototype, member)) {
newPrototype[member] = prototype[member];
}
}
}
}
for (var cls in pendingClasses) finishClass(cls);
};
Isolate.$finishIsolateConstructor = function(oldIsolate) {
var isolateProperties = oldIsolate.$isolateProperties;
var isolatePrototype = oldIsolate.prototype;
var str = "{\n";
str += "var properties = Isolate.$isolateProperties;\n";
for (var staticName in isolateProperties) {
if (Object.prototype.hasOwnProperty.call(isolateProperties, staticName)) {
str += "this." + staticName + "= properties." + staticName + ";\n";
}
}
str += "}\n";
var newIsolate = new Function(str);
newIsolate.prototype = isolatePrototype;
isolatePrototype.constructor = newIsolate;
newIsolate.$isolateProperties = isolateProperties;
return newIsolate;
};
}
//@ sourceMappingURL=dart.js.map
{
"version": 3,
"mappings": "A;;;;;;;;A;A;;A;A;A;A,E,Q,C,E,Q,C;A,kB,C;A,aAqBEA;AACE,SAAOC;CACT,A,C;A,YAEAC;AACE,SAAOD;CACT,A,C;A,QAKAE;YACeC;qBACOC;AAClB;EAEFC,QAAAA;EACAL,eAAQ,MAARA,cAAWI;AACX;CACF,A,C;A,UAuBAF;EACEG,eAAcC;EACdN;AACA;CACF,A,C;A,aAKAO;MACMF,aAAAA;AAAsB;MACtBA,aAAAA;AAAsB,mBAAOA;eACjBG,iCAA+BH;EAC/CA,QAAAA;EACAA,QAAAA;AAGA;CACF,A,C;A,qBApEAI;EACEC;EACAC;CACF,A;;;A;A,E,Q,C;A,kB,C;A,aCUAJ;WACMK;MAAQ;AACV,qCADEA;AAGJ;CACF,A;;;A;A,E,O,C;A,kB,C;A,aCVAL;AAAkB,wCAA+BM,IAAAA;CAAO,A;;;A;A,E,a,C,E,U,C;A,kB,C;A,aAkExDN;WACMO;;AACF,WAAOC;;AAEP,WAASA,IAAAA,8CAHPD,wDAKeE,IAAAA;CAErB,A,C;A,oBAEAT;AAAyB;CAAyB,A;;;A;A,E;A,kB,C;A,aASlDA;AAAkB;CAA4B,A;;;A;A,E,S,C;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AEhBQ;;cACiCjB,UAAAA;;AACnC;;YAEYvB;AACZ,gBAAkB;;MAEhBwC;;cACiCjB,UAAAA;;;;;AAEnC;AAEF;CACF,A;;A;A;A;A;A,O;;;;;A,S,wB,E,E;A,S,I;A,Q,I,+C,C,I,E,+B,C;A,iC,E;A;A;A;A;A;A;;;;;;;;;;;;;;;;;;;;;;;;;A;A;A;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;A;;;;;;A;A;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;A;;;;;;;;;;;;;;;;;A",
"sources": ["file:///Users/darthapo/Dev/dart/dart-sdk/lib/coreimpl/string_buffer.dart","file:///Users/darthapo/Dev/dart/dart-sdk/lib/core/errors.dart","file:///Users/darthapo/Dev/dart/dart-sdk/lib/core/exceptions.dart","file:///Users/darthapo/Dev/dart/dart-sdk/lib/core/object.dart","file:///Users/darthapo/Dev/dart/dart-sdk/pkg/compiler/implementation/lib/core_patch.dart","file:///Users/darthapo/Dev/dart/dart-sdk/pkg/compiler/implementation/lib/js_helper.dart","file:///Users/darthapo/Projects/Gists/compile-to-js-comparisions/source/simple.dart","file:///Users/darthapo/Dev/dart/dart-sdk/lib/coreimpl/maps.dart","file:///Users/darthapo/Dev/dart/dart-sdk/lib/core/string_buffer.dart","file:///Users/darthapo/Dev/dart/dart-sdk/pkg/compiler/implementation/lib/interceptors.dart","file:///Users/darthapo/Dev/dart/dart-sdk/lib/coreimpl/collections.dart","file:///Users/darthapo/Dev/dart/dart-sdk/pkg/compiler/implementation/lib/native_helper.dart","file:///Users/darthapo/Dev/dart/dart-sdk/pkg/compiler/implementation/lib/coreimpl_patch.dart","file:///Users/darthapo/Dev/dart/dart-sdk/pkg/compiler/implementation/lib/string_helper.dart"],
"names": ["int","_length","bool","StringBuffer","obj","str","_buffer","List","String","StringImplementation","StringBufferImpl","clear","add","message","_value","functionName","exceptionName","arguments","_message","Primitives","i","list","T","hasNext","NoMoreElementsException","greet","name","result","Collections","value","ArgumentError","factory","gt$slow","checkNumbers","a","checkGrowable","UnsupportedOperationException","$throw","iterator","isJsArray","ListIterator","receiver","add$1","static","visiting","_emitObject","set$length","checkNull","IndexOutOfRangeException","toStringWrapper","JS","checkNum","get$length","string","toString","index","index$slow","substring$2","substringUnchecked","removeLast","gtB","Simple","ltB","lt$slow","stringJoinUnchecked","_toJsStringArray","substring$1","NullPointerException","charCodeAt","objectTypeName","constructorNameFallback","_containsRef","_emitCollection","Maps","m","main","print","s","strings","add$slow","truncate","object","ceil","isEmpty","geB","ge$slow","ioore","floor"]
}
(function () { "use strict";
var Simple = function(name) {
this.name = name;
};
Simple.main = function() {
var s = new Simple("Flynn");
console.log(s.greet("Program"));
}
Simple.prototype = {
greet: function(who) {
return "Greetings " + who + ", I'm " + this.name + "!";
}
}
var Std = function() { }
Simple.main();
})();
//@ sourceMappingURL=haxe.js.map
{
"version":3,
"file":"haxe.js",
"sourceRoot":"file://",
"sources":["/Users/darthapo/Projects/Gists/compile-to-js-comparisions/source/simple.hx"],
"names":[],
"mappings":";SAMC,MAA0B;CACxB,EAAW;;cAON,HAAgB;CACrB,EAAe,QAAW;CAC1B,WAAO,XAAQ;;;OANjB,OAA2B;OAClB,AAAC,JAAW,AAAG,AAAO,AAAI;;;;;;;"
}
var JSX = {};
(function () {
/**
* copies the implementations from source interface to target
*/
function $__jsx_merge_interface(target, source) {
for (var k in source.prototype)
if (source.prototype.hasOwnProperty(k))
target.prototype[k] = source.prototype[k];
}
/**
* defers the initialization of the property
*/
function $__jsx_lazy_init(obj, prop, func) {
function reset(obj, prop, value) {
delete obj[prop];
obj[prop] = value;
return value;
}
Object.defineProperty(obj, prop, {
get: function () {
return reset(obj, prop, func());
},
set: function (v) {
reset(obj, prop, v);
},
enumerable: true,
configurable: true
});
}
/**
* sideeffect().a /= b
*/
function $__jsx_div_assign(obj, prop, divisor) {
return obj[prop] = (obj[prop] / divisor) | 0;
}
/*
* global functions called by JSX
* (enamed so that they do not conflict with local variable names)
*/
var $__jsx_parseInt = parseInt;
var $__jsx_parseFloat = parseFloat;
var $__jsx_isNaN = isNaN;
var $__jsx_isFinite = isFinite;
var $__jsx_encodeURIComponent = encodeURIComponent;
var $__jsx_decodeURIComponent = decodeURIComponent;
var $__jsx_encodeURI = encodeURI;
var $__jsx_decodeURI = decodeURI;
var $__jsx_ObjectToString = Object.prototype.toString;
var $__jsx_ObjectHasOwnProperty = Object.prototype.hasOwnProperty;
/*
* profiler object, initialized afterwards
*/
function $__jsx_profiler() {
}
/*
* public interface to JSX code
*/
JSX.require = function (path) {
var m = $__jsx_classMap[path];
return m !== undefined ? m : null;
};
JSX.profilerIsRunning = function () {
return $__jsx_profiler.getResults != null;
};
JSX.getProfileResults = function () {
return ($__jsx_profiler.getResults || function () { return {}; })();
};
JSX.postProfileResults = function (url) {
if ($__jsx_profiler.postResults == null)
throw new Error("profiler has not been turned on");
return $__jsx_profiler.postResults(url);
};
JSX.resetProfileResults = function () {
if ($__jsx_profiler.resetResults == null)
throw new Error("profiler has not been turned on");
return $__jsx_profiler.resetResults();
};
/**
* class Simple extends Object
* @constructor
*/
function Simple() {
}
Simple.prototype = new Object;
/**
* @constructor
* @param {!string} name
*/
function Simple$S(name) {
this.name = name;
};
Simple$S.prototype = new Simple;
/**
* @param {!string} who
* @return {!string}
*/
Simple.prototype.greet$S = function (who) {
return "Greetings " + who + ", I'm " + this.name + "!";
};
/**
* class _Main extends Object
* @constructor
*/
function _Main() {
}
_Main.prototype = new Object;
/**
* @constructor
*/
function _Main$() {
};
_Main$.prototype = new _Main;
/**
* @param {Array.<undefined|!string>} args
*/
_Main.main$AS = function (args) {
/** @type {Simple} */
var s;
s = new Simple$S("Flynn");
console.log(s.greet$S("Program"));
};
var _Main$main$AS = _Main.main$AS;
var $__jsx_classMap = {
"source/simple.jsx": {
Simple: Simple,
Simple$S: Simple$S,
_Main: _Main,
_Main$: _Main$
}
};
/**
* launches _Main.main(:string[]):void invoked by jsx --run|--executable
*/
JSX.runMain = function (sourceFile, args) {
var module = JSX.require(sourceFile);
if (! module._Main) {
throw new Error("entry point _Main not found in " + sourceFile);
}
if (! module._Main.main$AS) {
throw new Error("entry point _Main.main(:string[]):void not found in " + sourceFile);
}
module._Main.main$AS(args);
};
/**
* launches _Test#test*():void invoked by jsx --test
*/
JSX.runTests = function (sourceFile, tests) {
var module = JSX.require(sourceFile);
var testClass = module._Test$;
if (!testClass) return; // skip if there's no test class
if(tests.length === 0) {
var p = testClass.prototype;
for (var m in p) {
if (p[m] instanceof Function
&& /^test.*[$]$/.test(m)) {
tests.push(m);
}
}
}
else { // set as process arguments
tests = tests.map(function (name) {
return name + "$"; // mangle for function test*():void
});
}
var testCase = new testClass();
if (testCase.beforeClass$AS != null)
testCase.beforeClass$AS(tests);
for (var i = 0; i < tests.length; ++i) {
(function (method) {
if (method in testCase) {
testCase.run$SF$V$(method, function() { testCase[method](); });
}
else {
throw new ReferenceError("No such test method: " + method);
}
}(tests[i]));
}
if (testCase.afterClass$ != null)
testCase.afterClass$();
};
/**
* call a function on load/DOMContentLoaded
*/
function $__jsx_onload (event) {
window.removeEventListener("load", $__jsx_onload);
document.removeEventListener("DOMContentLoaded", $__jsx_onload);
JSX.runMain("source/simple.jsx", [])
}
window.addEventListener("load", $__jsx_onload);
document.addEventListener("DOMContentLoaded", $__jsx_onload);
})();
//@ sourceMappingURL=output/jsx.js.mapping
{"version":3,"file":"output/jsx.js","sources":["source/simple.jsx"],"names":["Simple","name","greet","who","_Main","main","args","s"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QACMA;;;;;;;;QAAAA,SAIiBC;AACnB,IAAKA,CAAAA,IAAK,GAAEA;;;;;;;;;gBAGLC,UAAT,UAAeC;OACN,YAAY,GAAEA,GAAI,GAAC,QAAQ,GAAE,IAAKF,CAAAA,IAAK,GAAC;;;;;;;QAK7CG;;;;;;;QAAAA;;;;;;;;KACYC,UAAT,UAAcC;;;AACfC,CAAC,GAAE,aAAW,OAAX;AACP,YAAIA,CAAEL,CAAAA,OAAK,CAAC,SAAD"}
.PHONY: compile
time=/usr/bin/time
compile: dart typescript coffeescript haxe jsx
dart:
$(time) dart2js -ooutput/dart.js source/simple.dart
typescript:
$(time) tsc --out output/typescript.js --sourcemap source/simple.ts
coffeescript:
$(time) coffee -p source/simple.coffee > output/coffee.js
haxe:
$(time) haxe -cp source/ -main Simple -js output/haxe.js --dead-code-elimination --js-modern -debug
jsx:
$(time) jsx --executable web --enable-source-map --output output/jsx.js source/simple.jsx
class Simple
constructor: (@name = "default") ->
greet: (who) ->
"Greetings #{ who }, I'm #{ @name }!"
@main: ->
s= new Simple "Flynn"
console.log s.greet "Program"
Simple.main()
class Simple {
String name;
Simple(this.name);
greet(who) => "Greetings $who, I'm $name!";
}
main() {
var s= new Simple('Flyn');
print( s.greet('Program'));
}
using Std;
class Simple {
var name:String;
function new(name:String) {
this.name= name;
}
function greet(who:String) {
return "Greetings $who, I'm $name!".format();
}
static function main() {
var s:Simple = new Simple("Flynn");
trace( s.greet("Program") );
}
}
class Simple {
var name:string;
function constructor(name:string) {
this.name = name;
}
function greet(who:string): string {
return "Greetings "+ who +", I'm "+ this.name +"!";
}
}
class _Main {
static function main(args:string[]):void {
var s= new Simple("Flynn");
log s.greet("Program");
}
}
class Simple {
constructor(public name: string) {}
greet(who: string) {
return "Greetings "+ who +", I'm "+ this.name +"!";
}
static main() {
var s = new Simple('Flynn');
console.log(s.greet("Program"));
}
}
Simple.main()
var Simple = (function () {
function Simple(name) {
this.name = name;
}
Simple.prototype.greet = function (who) {
return "Greetings " + who + ", I'm " + this.name + "!";
};
Simple.main = function main() {
var s = new Simple('Flynn');
console.log(s.greet("Program"));
}
return Simple;
})();
Simple.main();
//@ sourceMappingURL=typescript.js.map
{"version":3,"file":"typescript.js","sources":["simple.ts"],"names":[],"mappings":"AACA;IAEE,gBAAY;QAAO,YAAA;AAAgB;IAEnC,yBAAA,UAAM;QACJ,OAAO,eAAc,MAAK,WAAU,KAAK,OAAM;AAChD;IAED,cAAA;QACE,IAAI,IAAQ,IAAA,OAAO;QACnB,QAAQ,IAAI,EAAE,MAAM;AACrB;IAXH;;AAeA,OAAO"}
@lalamax3d
Copy link

thanks for sharing information in such precise manner

@chamberlainpi
Copy link

Coming from an ActionScript 3.0 background, I think TypeScript and Haxe are the two most attractive options here, especially looking at the minimal JS generated by their compilers. But given that Haxe can compile to other platforms / devices, I wonder if it's really worth the time to learn TypeScript.

@jcward
Copy link

jcward commented Oct 14, 2014

Haxe compile times also smoke the competition.

Ugliest output and 3 second compile, Dart, really? Google's losing it. =P =)

@PeyTy
Copy link

PeyTy commented Oct 14, 2014

Test needs to be updated. Newest TypeScript compiles faster, Haxe 3 has new shorter syntax

@elsassph
Copy link

Using Std isn't needed in the Haxe script. Output will be cleaner without.

@elsassph
Copy link

Anyway this comparision is useless: what about the real world when you have tens or hundreds of classes?

@skybrian
Copy link

skybrian commented Aug 5, 2015

FYI, there is a new Dart compiler being written [1] which will emit more idiomatic JavaScript. Perhaps someone can run it for comparison?

[1] https://github.com/dart-lang/dev_compiler

@skybrian
Copy link

skybrian commented Aug 5, 2015

Looks like Bob Nystrom posted the new compiler's output:

https://gist.github.com/munificent/bde42b3d02c563fb4a9c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment