Skip to content

Instantly share code, notes, and snippets.

@mgreter
Last active August 29, 2015 14:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgreter/355197a55dc6c8cac7d7 to your computer and use it in GitHub Desktop.
Save mgreter/355197a55dc6c8cac7d7 to your computer and use it in GitHub Desktop.
var sass = require('node-sass');
var elapsed_time = function(time) {
var elapsed = time[1] / 1000000;
console.log("libsass in ", time[0] + " s, " + elapsed.toFixed(3) + " ms");
}
var scss = '$main-font-size: 16px;';
for (var i = 0; i < 150; i++) {
scss += 'body { font-size: $main-font-size; }';
scss += 'h1 { font-size: $main-font-size * 2; }';
scss += 'pre { height: 100px - 2px; }';
}
var start = process.hrtime();
var result = sass.renderSync({
data: scss
});
var stop = process.hrtime(start);
// console.log(result.css);
elapsed_time(stop);
var fs = require("fs");
var postcss = require("postcss");
var calc = require("postcss-calc");
var vars = require("postcss-custom-properties");
var elapsed_time = function(time) {
var elapsed = time[1] / 1000000;
console.log("postcss in ", time[0] + " s, " + elapsed.toFixed(3) + " ms");
}
var css = ':root { --main-font-size: 16px; }';
for (var i = 0; i < 150; i++) {
css += 'body { font-size: var(--main-font-size); }';
css += 'h1 { font-size: calc(var(--main-font-size) * 2); }';
css += 'pre { height: calc(100px - 2px); }';
}
var start = process.hrtime();
var output = postcss()
.use(vars())
.use(calc())
.process(css)
.css
var stop = process.hrtime(start);
// console.log(output);
elapsed_time(stop);
libsass in 0 s, 135.280 ms
postcss in 0 s, 283.103 ms
# cat /proc/cpuinfo
vendor_id : GenuineIntel
cpu family : 6
model : 28
model name : Intel(R) Atom(TM) CPU 330 @ 1.60GHz
stepping : 2
microcode : 0x219
cpu MHz : 1596.074
cache size : 512 KB
# node -v
v0.10.30
# node-sass -v
node-sass 3.0.0-beta.7 (Wrapper) [JavaScript]
libsass 3.2.0-beta.6 (Sass Compiler) [C/C++]
# not sure how to fetch postcss version
# according to npm install it's 4.1.6
@ai
Copy link

ai commented Apr 28, 2015

I updated benchmark with more real examples: nesting, variables, mixins, math: https://github.com/postcss/postcss/blob/master/benchmark/general.js

But I got different result:

PostCSS:   47 ms
Rework:    77 ms   (1.7 times slower)
libsass:   128 ms  (2.7 times slower)
Less:      157 ms  (3.4 times slower)
Stylus:    189 ms  (4.1 times slower)
Ruby Sass: 1143 ms (24.5 times slower)

But I didn’t still use Bootstrap before mixins/variables. It contains comments, at-rules, whitespaces. It is a good test for real world parsing, so we can’t miss it.

@mgreter Can you check my updated benchmark. Maybe I loose something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment