Sha256: 25adebf72848f93a91348a98d773f5846929e4ca2be5ffd64be3ec22106d8e45

Contents?: true

Size: 1.82 KB

Versions: 94

Compression:

Stored size: 1.82 KB

Contents

"use strict";

var Q = require("../q");
var fs = require("fs");

suite("A single simple async operation", function () {
    bench("with an immediately-fulfilled promise", function (done) {
        Q().then(done);
    });

    bench("with direct setImmediate usage", function (done) {
        setImmediate(done);
    });

    bench("with direct setTimeout(…, 0)", function (done) {
        setTimeout(done, 0);
    });
});

suite("A fs.readFile", function () {
    var denodeified = Q.denodeify(fs.readFile);

    set("iterations", 1000);
    set("delay", 1000);

    bench("directly, with callbacks", function (done) {
        fs.readFile(__filename, done);
    });

    bench("with Q.nfcall", function (done) {
        Q.nfcall(fs.readFile, __filename).then(done);
    });

    bench("with a Q.denodeify'ed version", function (done) {
        denodeified(__filename).then(done);
    });

    bench("with manual usage of deferred.makeNodeResolver", function (done) {
        var deferred = Q.defer();
        fs.readFile(__filename, deferred.makeNodeResolver());
        deferred.promise.then(done);
    });
});

suite("1000 operations in parallel", function () {
    function makeCounter(desiredCount, ultimateCallback) {
        var soFar = 0;
        return function () {
            if (++soFar === desiredCount) {
                ultimateCallback();
            }
        };
    }
    var numberOfOps = 1000;

    bench("with immediately-fulfilled promises", function (done) {
        var counter = makeCounter(numberOfOps, done);

        for (var i = 0; i < numberOfOps; ++i) {
            Q().then(counter);
        }
    });

    bench("with direct setImmediate usage", function (done) {
        var counter = makeCounter(numberOfOps, done);

        for (var i = 0; i < numberOfOps; ++i) {
            setImmediate(counter);
        }
    });
});

Version data entries

94 entries across 80 versions & 4 rubygems

Version Path
trusty-festivity-extension-2.6.3 node_modules/bower/node_modules/p-throttler/node_modules/q/benchmark/compare-with-callbacks.js
trusty-festivity-extension-2.6.2 node_modules/bower/node_modules/p-throttler/node_modules/q/benchmark/compare-with-callbacks.js
trusty-festivity-extension-2.6.1 node_modules/bower/node_modules/p-throttler/node_modules/q/benchmark/compare-with-callbacks.js
trusty-festivity-extension-2.6 node_modules/bower/node_modules/p-throttler/node_modules/q/benchmark/compare-with-callbacks.js
trusty-festivity-extension-2.5.19 node_modules/bower/node_modules/p-throttler/node_modules/q/benchmark/compare-with-callbacks.js
trusty-festivity-extension-2.5.18 node_modules/bower/node_modules/p-throttler/node_modules/q/benchmark/compare-with-callbacks.js
trusty-festivity-extension-2.5.17 node_modules/bower/node_modules/p-throttler/node_modules/q/benchmark/compare-with-callbacks.js
trusty-festivity-extension-2.5.16 node_modules/bower/node_modules/p-throttler/node_modules/q/benchmark/compare-with-callbacks.js
trusty-festivity-extension-2.5.15 node_modules/bower/node_modules/p-throttler/node_modules/q/benchmark/compare-with-callbacks.js
trusty-festivity-extension-2.5.14 node_modules/bower/node_modules/p-throttler/node_modules/q/benchmark/compare-with-callbacks.js
trusty-festivity-extension-2.5.13 node_modules/bower/node_modules/p-throttler/node_modules/q/benchmark/compare-with-callbacks.js
trusty-festivity-extension-2.5.12 node_modules/bower/node_modules/p-throttler/node_modules/q/benchmark/compare-with-callbacks.js
trusty-festivity-extension-2.5.11 node_modules/bower/node_modules/p-throttler/node_modules/q/benchmark/compare-with-callbacks.js
trusty-festivity-extension-2.5.10 node_modules/bower/node_modules/p-throttler/node_modules/q/benchmark/compare-with-callbacks.js
trusty-festivity-extension-2.5.9 node_modules/bower/node_modules/p-throttler/node_modules/q/benchmark/compare-with-callbacks.js
trusty-festivity-extension-2.5.8 node_modules/bower/node_modules/p-throttler/node_modules/q/benchmark/compare-with-callbacks.js
trusty-festivity-extension-2.5.7 node_modules/bower/node_modules/p-throttler/node_modules/q/benchmark/compare-with-callbacks.js
trusty-festivity-extension-2.5.6 node_modules/bower/node_modules/p-throttler/node_modules/q/benchmark/compare-with-callbacks.js
trusty-festivity-extension-2.5.5 node_modules/bower/node_modules/p-throttler/node_modules/q/benchmark/compare-with-callbacks.js
trusty-festivity-extension-2.5.4 node_modules/bower/node_modules/p-throttler/node_modules/q/benchmark/compare-with-callbacks.js