This repository has been archived by the owner on Mar 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
index.js
65 lines (58 loc) · 1.74 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var nopt = require('nopt'),
fs = require('fs'),
_ = require('underscore'),
langs = {},
files = fs.readdirSync(__dirname + '/lib/languages/'),
options = {
type: String,
template: String,
time: Number,
comparisons: Number
},
shortOpts = {
t: ['--type'],
tt: ['--template'],
m: ['--time'],
c: ['--comparisons']
},
parsed = nopt(options, shortOpts, process.argv, 2),
templateType = parsed.template || 'simple';
exports.time = parsed.time || 1000;
exports.compareCount = parsed.comparisons || 8;
_.each(files, function (file) {
langs[file.replace('.js', '')] = require(__dirname + '/lib/languages/' + file);
});
exports.compare = (function () {
var cases = {};
// return {
// LANG: function (callback) {
// langs.LANG.compile(templateType, function () {
// langs.LANG.render(templateType, callback);
// });
// }
// }
_.each(langs, function (lang, key) {
switch (parsed.type) {
case 'compile':
cases[key + ' compile'] = function (callback) {
lang.compile(templateType, callback);
};
break;
case 'render':
lang.compile(templateType, function () {});
cases[key + ' render'] = function (callback) {
lang.render(templateType, callback);
};
break;
default:
cases[key + ' complete'] = function (callback) {
lang.compile(templateType, function () {
lang.render(templateType, callback);
});
};
break;
}
});
return cases;
}());
require('bench').runMain();