'use strict';

const Benchmark = require('Benchmark');
const series = require('promise-map-series');

const fixtures = require('./fixtures');

const walk = require('../lib');
const enb = require('./enb');
const scanl = require('./scan-level');

const cases = [
    { name: 'flat level',     levels: fixtures.levels.flat,    scheme: 'flat' },
    { name: 'nested level',   levels: fixtures.levels.nested,  scheme: 'nested' },
    { name: 'bem-bl',         levels: fixtures.libs['bem-bl'], scheme: 'nested' },
    { name: 'bem-components', levels: fixtures.libs.o2,        scheme: 'nested' }
];

series(cases, item => {
    return new Promise(resolve => {
        const suite = new Benchmark.Suite(item.name);

        suite
            .add('bem-walk', deferred => {
                walk(item.levels, { defaults: { scheme: item.scheme } })
                    .resume().on('end', () => deferred.resolve());
            }, { defer: true })
            .add('     enb', deferred => {
                enb(item.levels, item.scheme, () => deferred.resolve());
            }, { defer: true })
            .add('   scanl', deferred => {
                scanl(item.levels, item.scheme, () => deferred.resolve());
            }, { defer: true })
            .on('start', () => {
                console.log('         ' + item.name)
            })
            .on('cycle', event => {
                const target = event.target;
                const mean = target.stats.mean * 1000;

                console.log(`${target} mean ${mean.toFixed(2)} ms`);
            })
            .on('complete', () => {
                console.log('');
                resolve();
            })
            .run();
    });
});

@@ -8,16 +8,77 @@
 rict';%0A%0A
+const fs = require('fs');%0Aconst stream = require('stream');%0A%0A
 const Be
@@ -150,24 +150,81 @@
 ap-series');
+%0Aconst stringifyEntity = require('bem-naming').stringify;
 %0A%0Aconst fixt
@@ -852,16 +852,32 @@
   .add('
+                
 bem-walk
@@ -1079,24 +1079,1647 @@
       .add('
+    bem-walk + fs.stat()', deferred =%3E %7B%0A                const data = %7B%7D;%0A%0A                walk(item.levels, %7B defaults: %7B scheme: item.scheme %7D %7D)%0A                    .pipe(new stream.Writable(%7B%0A                        objectMode: true,%0A                        write: function (file, encoding, callback) %7B%0A                            fs.stat(file.path, (err, stats) =%3E %7B%0A                                if (err) %7B%0A                                    return callback(err);%0A                                %7D%0A%0A                                const id = stringifyEntity(file.entity);%0A%0A                                file.stat = stats;%0A                                data%5Bid%5D = file;%0A%0A                                callback();%0A                            %7D);%0A                        %7D%0A                    %7D))%0A                    .on('error', err =%3E deferred.reject(err))%0A                    .on('finish', () =%3E deferred.resolve());%0A            %7D, %7B defer: true %7D)%0A            .add('bem-walk + fs.statSync()', deferred =%3E %7B%0A                const data = %7B%7D;%0A%0A                walk(item.levels, %7B defaults: %7B scheme: item.scheme %7D %7D)%0A                    .on('data', file =%3E %7B%0A                        const id = stringifyEntity(file.entity);%0A                        const stats = fs.statSync(file.path);%0A%0A                        file.stat = stats;%0A                        data%5Bid%5D = file;%0A                    %7D)%0A                    .resume()%0A                    .on('error', err =%3E deferred.reject(err))%0A                    .on('end', () =%3E deferred.resolve());%0A            %7D, %7B defer: true %7D)%0A            .add('                
      enb', d
@@ -2854,16 +2854,32 @@
   .add('
+                
    scanl
@@ -3064,16 +3064,32 @@
 le.log('
+                
         

add cases with `fs.stat()` and `fs.statSync` for `bem-walk`