carto/benchmark/less-benchmark.js

52 lines
1.6 KiB
JavaScript
Raw Normal View History

2010-02-26 07:02:07 +08:00
var path = require('path'),
fs = require('fs'),
sys = require('sys');
require.paths.unshift(__dirname, path.join(__dirname, '..'));
2010-03-20 05:50:10 +08:00
var less = require('lib/less');
2010-02-26 07:02:07 +08:00
var file = path.join(__dirname, 'benchmark.less');
fs.stat(file, function (e, stats) {
fs.open(file, process.O_RDONLY, stats.mode, function (e, fd) {
fs.read(fd, stats.size, 0, "utf8", function (e, data) {
2010-02-26 08:47:26 +08:00
var tree, css, start, end, total;
sys.puts("Bechmarking...\n", path.basename(file) + " (" +
parseInt(data.length / 1024) + " KB)", "");
2010-02-26 07:02:07 +08:00
start = new(Date);
less.parser.parse(data, function (err, tree) {
end = new(Date);
2010-03-06 01:08:01 +08:00
total = end - start;
2010-02-26 08:47:26 +08:00
sys.puts("Parsing: " +
total + " ms (" +
parseInt(1000 / total *
data.length / 1024) + " KB\/s)");
2010-02-26 07:02:07 +08:00
start = new(Date);
css = tree.toCSS([], {frames: []});
end = new(Date);
sys.puts("Generation: " + (end - start) + " ms (" +
parseInt(1000 / (end - start) *
data.length / 1024) + " KB\/s)");
2010-02-26 07:02:07 +08:00
total += end - start;
2010-02-26 08:47:26 +08:00
sys.puts("Total: " + total + "ms (" +
parseInt(1000 / total * data.length / 1024) + " KB/s)");
2010-02-26 08:47:26 +08:00
if (err) {
process.stdio.writeError(err.message);
process.exit(3);
}
});
2010-02-26 07:02:07 +08:00
});
});
});