File: bm.js

package info (click to toggle)
node-stylus 0.54.5-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 5,392 kB
  • ctags: 913
  • sloc: makefile: 38
file content (63 lines) | stat: -rw-r--r-- 1,372 bytes parent folder | download | duplicates (3)
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

/**
 * Module dependencies.
 */

var stylus = require('./')
  , fs = require('fs');

var times = ~~process.env.TIMES || 1
  , avgs = [];

// test cases

var cases = fs.readdirSync('test/cases').filter(function(file){
  return ~file.indexOf('.styl');
}).map(function(file){
  return file.replace('.styl', '');
});

console.log();
cases.forEach(function(test){
  var name = test.replace(/[-.]/g, ' ');
  var path = 'test/cases/' + test + '.styl';
  var styl = fs.readFileSync(path, 'utf8').replace(/\r/g, '');

  var style = stylus(styl)
    .set('filename', path)
    .include(__dirname + '/test/images')
    .include(__dirname + '/test/cases/import.basic')
    .define('url', stylus.url());

  if (~test.indexOf('compress')) style.set('compress', true);

  var runs = []
    , n = times
    , start;

  while (n--) {
    start = new Date;
    style.render(function(err){
      if (err) throw err;
    });
    runs.push(new Date - start);
  }

  var avg = runs.reduce(function(sum, n){
    return sum + n;
  }) / times;

  avgs.push(avg);

  // im cool like that
  var avgavg = avgs.reduce(function(sum, n){
    return sum + n;
  }) / avgs.length;

  if (avg > avgavg) {
    console.log('  \033[31m%s \033[31m%dms \033[90m+%dms\033[0m', name, avg | 0, avg - avgavg | 0);
  } else {
    console.log('  \033[36m%s \033[90m%dms\033[0m', name, avg | 0);
  }
});
console.log();