"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/q/benchmark/compare-with-callbacks.js" (11 Apr 2017, 1859 Bytes) of package /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 "use strict";
    2 
    3 var Q = require("../q");
    4 var fs = require("fs");
    5 
    6 suite("A single simple async operation", function () {
    7     bench("with an immediately-fulfilled promise", function (done) {
    8         Q().then(done);
    9     });
   10 
   11     bench("with direct setImmediate usage", function (done) {
   12         setImmediate(done);
   13     });
   14 
   15     bench("with direct setTimeout(…, 0)", function (done) {
   16         setTimeout(done, 0);
   17     });
   18 });
   19 
   20 suite("A fs.readFile", function () {
   21     var denodeified = Q.denodeify(fs.readFile);
   22 
   23     set("iterations", 1000);
   24     set("delay", 1000);
   25 
   26     bench("directly, with callbacks", function (done) {
   27         fs.readFile(__filename, done);
   28     });
   29 
   30     bench("with Q.nfcall", function (done) {
   31         Q.nfcall(fs.readFile, __filename).then(done);
   32     });
   33 
   34     bench("with a Q.denodeify'ed version", function (done) {
   35         denodeified(__filename).then(done);
   36     });
   37 
   38     bench("with manual usage of deferred.makeNodeResolver", function (done) {
   39         var deferred = Q.defer();
   40         fs.readFile(__filename, deferred.makeNodeResolver());
   41         deferred.promise.then(done);
   42     });
   43 });
   44 
   45 suite("1000 operations in parallel", function () {
   46     function makeCounter(desiredCount, ultimateCallback) {
   47         var soFar = 0;
   48         return function () {
   49             if (++soFar === desiredCount) {
   50                 ultimateCallback();
   51             }
   52         };
   53     }
   54     var numberOfOps = 1000;
   55 
   56     bench("with immediately-fulfilled promises", function (done) {
   57         var counter = makeCounter(numberOfOps, done);
   58 
   59         for (var i = 0; i < numberOfOps; ++i) {
   60             Q().then(counter);
   61         }
   62     });
   63 
   64     bench("with direct setImmediate usage", function (done) {
   65         var counter = makeCounter(numberOfOps, done);
   66 
   67         for (var i = 0; i < numberOfOps; ++i) {
   68             setImmediate(counter);
   69         }
   70     });
   71 });