Permalink
Browse files

Initial release.

  • Loading branch information...
jakubpawlowicz committed Oct 31, 2013
0 parents commit 122309ff25e11278cf81110c5ff838dd0b0d8450
Showing with 4,695 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +7 −0 LICENSE
  3. +47 −0 README.md
  4. +112 −0 bin/bench
  5. +602 −0 data/960.css
  6. +470 −0 data/apple.com.css
  7. +1 −0 data/bbc.co.uk.css
  8. +556 −0 data/blueprint.css
  9. +30 −0 data/cnn.com.css
  10. +2,824 −0 data/facebook.com.css
  11. +1 −0 data/twitter.com.css
  12. +19 −0 data/yahoo.com.css
  13. +24 −0 package.json
@@ -0,0 +1,2 @@
+.DS_Store
+node_modules
@@ -0,0 +1,7 @@
+Copyright (c) 2013 GoalSmashers.com
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,47 @@
+[![devDependency Status](https://david-dm.org/GoalSmashers/css-minification-benchmark/dev-status.png)](https://david-dm.org/GoalSmashers/css-minification-benchmark#info=devDependencies)
+
+## What is css-minification-benchmark?
+
+A comparison of CSS minification engines.
+
+## FAQ
+
+### Which engines are covered?
+
+* [clean-css](https://github.com/GoalSmashers/clean-css)
+* [csso](https://github.com/css/csso)
+* [ncss](https://github.com/kurakin/ncss)
+* [ycssmin](https://github.com/yui/ycssmin)
+
+### What are the results?
+
+Most of the time either `clean-css` or `csso` comes first. Although it depends on a particular CSS file.
+
+### How can I see the results?
+
+Clone the repository first then run `./bin/bench`. That's it!
+
+### How can I test my CSS file?
+
+Just copy your file to `data` directory (make sure filename ends with `.css`) and re-run the benchmark.
+
+Please make sure your file does not contain any special comments (`/*! ... */`) since not all minifiers strip them correctly:
+* `clean-css` has it configurable but leaves all by default
+* `csso` always leaves one
+* `ncss` and `ycssmin` always leave all
+
+### How can I add a new minifier to the list?
+
+* add it to `package.json` as a `devDependency`
+* run `npm install`
+* require it in `bin/bench` and add it to `minifiers` hash
+* re-run the benchmark
+* send a PR (if you wish to have it included)
+
+### How can I compare a subset of minifiers
+
+Just run `./bin/bench --only ncss,ycssmin` (it's turned into `/.*(ncss|ycsmin).*/` regex)
+
+## License
+
+css-minification-benchmark is released under the [MIT License](https://github.com/GoalSmashers/clean-css/blob/master/LICENSE).
112 bin/bench
@@ -0,0 +1,112 @@
+#!/usr/bin/env node
+
+// mock it to drop output from ncss
+var output = process.stdout.write.bind(process.stdout);
+process.stdout.write = function(data) {
+ if (data == '.' || data == 'F')
+ output(data);
+};
+
+var CleanCSS = require('clean-css');
+var csso = require('csso');
+var ncss = require('ncss');
+var ycssmin = require('ycssmin');
+
+var Table = require('cli-table');
+var fs = require('fs');
+var path = require('path');
+var colors = require('colors');
+
+// MINIFIERS
+
+var minifiers = {
+ 'clean-css': function(source) {
+ return new CleanCSS().minify(source);
+ },
+ 'clean-css (advanced off)': function(source) {
+ return new CleanCSS({ noAdvanced: true }).minify(source);
+ },
+ 'csso': csso.justDoIt,
+ 'csso (reordering off)': function(source) {
+ return csso.justDoIt(source, true);
+ },
+ 'ncss': ncss,
+ 'ycssmin': ycssmin.cssmin
+};
+var activeMinifiers = [];
+var only = process.argv[2] == '--only' ?
+ new RegExp('.*(' + process.argv[3].replace(/,/g, '|') + ').*') :
+ /.+/;
+
+for (var name in minifiers) {
+ if (only.test(name))
+ activeMinifiers.push(name);
+}
+
+// RUN BENCHMARK
+var minifierNames = activeMinifiers.slice(0);
+minifierNames.unshift('');
+
+var results = new Table({ head: minifierNames });
+
+var comparator = function(n1, n2) {
+ return n1 > n2 ? 1 : -1;
+};
+var benchmark = function(filename) {
+ if (filename.indexOf('.css') == -1)
+ return;
+
+ var source = fs.readFileSync(path.join('data', filename), 'utf8');
+ var row = [filename + ' (' + source.length + ' bytes)'];
+ var sizes = [];
+ var times = [];
+
+ activeMinifiers.forEach(function(name) {
+ try {
+ var start = process.hrtime();
+ var minified = minifiers[name](source);
+ var itTook = process.hrtime(start);
+ var took = ~~(1000 * itTook[0] + itTook[1] / 1000000.0);
+
+ sizes.push(minified.length);
+ times.push(took);
+ row.push({ size: minified.length, time: took });
+ process.stdout.write('.');
+ } catch (e) {
+ row.push({ size: -1, time: -1 });
+ process.stdout.write('F');
+ }
+ });
+
+ sizes = sizes.sort(comparator);
+ times = times.sort(comparator);
+
+ row = row.map(function(result) {
+ if (result.time == -1)
+ return 'error'.red.inverse;
+ if (typeof result == 'string')
+ return result;
+
+ var size = '' + result.size;
+ if (result.size == sizes[sizes.length - 1] && sizes.length > 1 && sizes[0] != sizes[sizes.length - 1])
+ size = size.red
+ if (result.size == sizes[0])
+ size = size.green
+
+ var time = '' + result.time;
+ if (result.time == times[times.length - 1] && times.length > 1 && times[0] != times[times.length - 1])
+ time = time.red
+ if (result.time == times[0])
+ time = time.green
+
+ return size + ' bytes (' + time + ' ms)';
+ });
+
+ results.push(row);
+};
+
+fs.readdirSync('data').forEach(benchmark);
+
+output('\n');
+output(results.toString());
+output('\n');
Oops, something went wrong.

0 comments on commit 122309f

Please sign in to comment.