Last active
August 29, 2015 14:16
-
-
Save teppeis/68baae014137778b76c4 to your computer and use it in GitHub Desktop.
typescript-simple benchmark vs. coffee-script
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
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'); |
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
{ | |
"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" | |
} | |
} |
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
typescript-simple warm up 556ms | |
typescript-simple 1264ms | |
coffee-script 798ms |
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
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) |
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
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); |
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
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() |
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
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