summaryrefslogtreecommitdiff
path: root/fetcher/node_modules/asynckit/bench.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-05-08 13:18:04 +0200
committerMinteck <contact@minteck.org>2022-05-08 13:18:04 +0200
commit16da8f48c7328c334a5c0d863078fd00257ae6b4 (patch)
tree4ab80e4106c4c7a61e5a7caf6102d612b8dd985d /fetcher/node_modules/asynckit/bench.js
downloaddownloadcenter-16da8f48c7328c334a5c0d863078fd00257ae6b4.tar.gz
downloadcenter-16da8f48c7328c334a5c0d863078fd00257ae6b4.tar.bz2
downloadcenter-16da8f48c7328c334a5c0d863078fd00257ae6b4.zip
Initial commit
Diffstat (limited to 'fetcher/node_modules/asynckit/bench.js')
-rw-r--r--fetcher/node_modules/asynckit/bench.js76
1 files changed, 76 insertions, 0 deletions
diff --git a/fetcher/node_modules/asynckit/bench.js b/fetcher/node_modules/asynckit/bench.js
new file mode 100644
index 0000000..c612f1a
--- /dev/null
+++ b/fetcher/node_modules/asynckit/bench.js
@@ -0,0 +1,76 @@
+/* eslint no-console: "off" */
+
+var asynckit = require('./')
+ , async = require('async')
+ , assert = require('assert')
+ , expected = 0
+ ;
+
+var Benchmark = require('benchmark');
+var suite = new Benchmark.Suite;
+
+var source = [];
+for (var z = 1; z < 100; z++)
+{
+ source.push(z);
+ expected += z;
+}
+
+suite
+// add tests
+
+.add('async.map', function(deferred)
+{
+ var total = 0;
+
+ async.map(source,
+ function(i, cb)
+ {
+ setImmediate(function()
+ {
+ total += i;
+ cb(null, total);
+ });
+ },
+ function(err, result)
+ {
+ assert.ifError(err);
+ assert.equal(result[result.length - 1], expected);
+ deferred.resolve();
+ });
+}, {'defer': true})
+
+
+.add('asynckit.parallel', function(deferred)
+{
+ var total = 0;
+
+ asynckit.parallel(source,
+ function(i, cb)
+ {
+ setImmediate(function()
+ {
+ total += i;
+ cb(null, total);
+ });
+ },
+ function(err, result)
+ {
+ assert.ifError(err);
+ assert.equal(result[result.length - 1], expected);
+ deferred.resolve();
+ });
+}, {'defer': true})
+
+
+// add listeners
+.on('cycle', function(ev)
+{
+ console.log(String(ev.target));
+})
+.on('complete', function()
+{
+ console.log('Fastest is ' + this.filter('fastest').map('name'));
+})
+// run async
+.run({ 'async': true });