"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/asynckit/bench.js" (7 Feb 2017, 1256 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* eslint no-console: "off" */
    2 
    3 var asynckit = require('./')
    4   , async    = require('async')
    5   , assert   = require('assert')
    6   , expected = 0
    7   ;
    8 
    9 var Benchmark = require('benchmark');
   10 var suite = new Benchmark.Suite;
   11 
   12 var source = [];
   13 for (var z = 1; z < 100; z++)
   14 {
   15   source.push(z);
   16   expected += z;
   17 }
   18 
   19 suite
   20 // add tests
   21 
   22 .add('async.map', function(deferred)
   23 {
   24   var total = 0;
   25 
   26   async.map(source,
   27   function(i, cb)
   28   {
   29     setImmediate(function()
   30     {
   31       total += i;
   32       cb(null, total);
   33     });
   34   },
   35   function(err, result)
   36   {
   37     assert.ifError(err);
   38     assert.equal(result[result.length - 1], expected);
   39     deferred.resolve();
   40   });
   41 }, {'defer': true})
   42 
   43 
   44 .add('asynckit.parallel', function(deferred)
   45 {
   46   var total = 0;
   47 
   48   asynckit.parallel(source,
   49   function(i, cb)
   50   {
   51     setImmediate(function()
   52     {
   53       total += i;
   54       cb(null, total);
   55     });
   56   },
   57   function(err, result)
   58   {
   59     assert.ifError(err);
   60     assert.equal(result[result.length - 1], expected);
   61     deferred.resolve();
   62   });
   63 }, {'defer': true})
   64 
   65 
   66 // add listeners
   67 .on('cycle', function(ev)
   68 {
   69   console.log(String(ev.target));
   70 })
   71 .on('complete', function()
   72 {
   73   console.log('Fastest is ' + this.filter('fastest').map('name'));
   74 })
   75 // run async
   76 .run({ 'async': true });