Skip to content

Instantly share code, notes, and snippets.

@teppeis
Last active August 29, 2015 14:16
Show Gist options
  • Save teppeis/68baae014137778b76c4 to your computer and use it in GitHub Desktop.
Save teppeis/68baae014137778b76c4 to your computer and use it in GitHub Desktop.
typescript-simple benchmark vs. coffee-script
var fs = require('fs');
var TS = require('typescript-simple').TypeScriptSimple;
var cs = require('coffee-script');
var tss = new TS({noImplicitAny: true});
var sample1 = fs.readFileSync('./sample1.ts', {encoding: 'utf8'});
var sample2 = fs.readFileSync('./sample2.ts', {encoding: 'utf8'});
// warm up
var start = new Date().getTime();
tss.compile(sample2);
console.log('typescript-simple warm up', new Date().getTime() - start + 'ms');
start = new Date().getTime();
for (var i = 0; i < 100; i++) {
tss.compile(sample1);
tss.compile(sample2);
}
console.log('typescript-simple', new Date().getTime() - start + 'ms');
sample1 = fs.readFileSync('./sample1.coffee', {encoding: 'utf8'});
sample2 = fs.readFileSync('./sample2.coffee', {encoding: 'utf8'});
start = new Date().getTime();
for (var i = 0; i < 100; i++) {
cs.compile(sample1);
cs.compile(sample2);
}
console.log('coffee-script', new Date().getTime() - start + 'ms');
{
"name": "typescript-simple-bench",
"version": "1.0.0",
"description": "typescript-simple benchmark vs. coffee-script",
"main": "bench.js",
"scripts": {
"test": "node ./bench.js"
},
"repository": {
"type": "git",
"url": "https://gist.github.com/68baae014137778b76c4.git"
},
"keywords": [
"typescirpt",
"coffee-script"
],
"author": "Teppei Sato <[email protected]>",
"license": "MIT",
"dependencies": {
"coffee-script": "^1.9.1",
"typescript-simple": "^0.2.0"
}
}
typescript-simple warm up 556ms
typescript-simple 1264ms
coffee-script 798ms
class Greeter
greeting
constructor: (message) ->
@greeting = message
greet: () ->
@greeting
greeter = new Greeter("Hello, world")
button = document.createElement('button')
button.textContent = "Say Hello"
button.onclick = () ->
alert(greeter.greet())
document.body.appendChild(button)
class Greeter<T> {
greeting: T;
constructor(message: T) {
this.greeting = message;
}
greet() {
return this.greeting;
}
}
var greeter = new Greeter<string>("Hello, world");
var button = document.createElement('button');
button.textContent = "Say Hello";
button.onclick = function () {
alert(greeter.greet());
}
document.body.appendChild(button);
class Animal
constructor: (@name) ->
move: (meters) ->
alert @name + " moved #{meters}m."
class Snake extends Animal
move: ->
alert "Slithering..."
super 5
class Horse extends Animal
move: ->
alert "Galloping..."
super 45
sam = new Snake "Sammy the Python"
tom = new Horse "Tommy the Palomino"
sam.move()
tom.move()
class Animal {
constructor(public name: string) { }
move(meters: number) {
alert(this.name + " moved " + meters + "m.");
}
}
class Snake extends Animal {
constructor(name: string) { super(name); }
move() {
alert("Slithering...");
super.move(5);
}
}
class Horse extends Animal {
constructor(name: string) { super(name); }
move() {
alert("Galloping...");
super.move(45);
}
}
var sam = new Snake("Sammy the Python");
var tom: Animal = new Horse("Tommy the Palomino");
sam.move();
tom.move(34);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment