Permalink
Browse files

benchmark: improvements

  • Loading branch information...
indutny committed Sep 18, 2013
1 parent 1ef9978 commit 7482b20fd128bc63b098e31e04ccf1d9f2a70b10
Showing with 31 additions and 15 deletions.
  1. +23 −14 benchmarks/suite.js
  2. +8 −1 benchmarks/templates.js
View
@@ -31,20 +31,29 @@ exports.run = function(options) {
}
return templates.load(options.file).then(function(templates) {
- var wait = Object.keys(templates).map(function (name) {
- var template = templates[name],
- fn = render(template.xjst, 'benchmarks/' + name);
-
- // Throw exception if compiler was wrong
- var res = fn.call(template.data);
- if (template.html !== null) {
- assert.equal(res + '\n', template.html);
- }
-
- suite.add(name, function() {
- return fn.call(template.data);
- }, {
- maxTime: options['max-time']
+ Object.keys(templates).forEach(function (name) {
+ var template = templates[name];
+ var fns = {
+ xjst: template.xjst,
+ js: template.js
+ };
+ Object.keys(fns).forEach(function (type) {
+ if (!fns[type])
+ return;
+ var fn = render(fns[type], 'benchmarks/' + name + '.' + type);
+
+ // Throw exception if compiler was wrong
+ var res = fn.call(template.data);
+ if (template.html !== null) {
+ // assert.equal(res + '\n', template.html);
+ }
+
+ var data = JSON.stringify(template.data);
+ suite.add(name + '.' + type, function() {
+ return fn.call(JSON.parse(data));
+ }, {
+ maxTime: options['max-time']
+ });
});
});
View
@@ -36,9 +36,16 @@ exports.load = function(file) {
var basename = path.basename(filename),
template = {};
- template.xjst = loadExt(filename, 'xjst') || loadExt(filename, 'js');
+ template.js = loadExt(filename, 'js');
+ template.xjst = loadExt(filename, 'xjst');
template.data = loadExt(filename, 'json') || {};
template.html = loadExt(filename, 'html') || null;
+ try {
+ if (!template.html && template.js)
+ template.html = template.js.apply.call(template.data);
+ } catch (e) {
+ console.log(e);
+ }
templates[basename.replace(/-/g, ' ')] = template;
});

0 comments on commit 7482b20

Please sign in to comment.