From e2bef5c00fe69837ce1925a1663e8fb702913873 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Mon, 3 Apr 2017 21:14:43 +0300 Subject: [PATCH] benchmark: use object literal shorthands --- benchmark/common.js | 2 +- benchmark/es/object-shorthands.js | 60 +++++++++++++++++++ benchmark/fs/read-stream-throughput.js | 2 +- benchmark/http/cluster.js | 2 +- benchmark/http/create-clientrequest.js | 2 +- benchmark/http/simple.js | 2 +- .../misc/util-extend-vs-object-assign.js | 2 +- benchmark/misc/v8-bench.js | 8 +-- 8 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 benchmark/es/object-shorthands.js diff --git a/benchmark/common.js b/benchmark/common.js index 77ebe0bd1dc37f..bbad012f49f54f 100644 --- a/benchmark/common.js +++ b/benchmark/common.js @@ -230,7 +230,7 @@ Benchmark.prototype.report = function(rate, elapsed) { sendResult({ name: this.name, conf: this.config, - rate: rate, + rate, time: elapsed[0] + elapsed[1] / 1e9, type: 'report' }); diff --git a/benchmark/es/object-shorthands.js b/benchmark/es/object-shorthands.js new file mode 100644 index 00000000000000..b2301ec3a7aa8b --- /dev/null +++ b/benchmark/es/object-shorthands.js @@ -0,0 +1,60 @@ +'use strict'; + +const common = require('../common.js'); + +const configs = { + n: [1e4], + mode: ['full', 'short'], + subject: ['properties', 'methods'], +}; + +const bench = common.createBenchmark(main, configs); + +function main(conf) { + const n = +conf.n; + + let obj; + + if (conf.mode === 'properties') { + const a = 'a'; + const b = 1; + const c = {}; + const d = () => {}; + + if (conf.mode === 'full') { + bench.start(); + for (let i = 0; i < n; i++) + obj = { a: a, b: b, c: c, d: d }; + bench.end(n); + } else { + bench.start(); + for (let i = 0; i < n; i++) + obj = { a, b, c, d }; + bench.end(n); + } + } else { + if (conf.mode === 'full') { + bench.start(); + for (let i = 0; i < n; i++) + obj = { + a: function a() {}, + b: function b() {}, + c: function c() {}, + d: function d() {}, + }; + bench.end(n); + } else { + bench.start(); + for (let i = 0; i < n; i++) + obj = { + a() {}, + b() {}, + c() {}, + d() {}, + }; + bench.end(n); + } + } + + return obj; +} diff --git a/benchmark/fs/read-stream-throughput.js b/benchmark/fs/read-stream-throughput.js index bc55e44c1a18d7..546e42d75e00d0 100644 --- a/benchmark/fs/read-stream-throughput.js +++ b/benchmark/fs/read-stream-throughput.js @@ -40,7 +40,7 @@ function runTest() { assert(fs.statSync(filename).size === filesize); var rs = fs.createReadStream(filename, { highWaterMark: size, - encoding: encoding + encoding }); rs.on('open', function() { diff --git a/benchmark/http/cluster.js b/benchmark/http/cluster.js index 732a5fad6646c9..e546ac96be0a36 100644 --- a/benchmark/http/cluster.js +++ b/benchmark/http/cluster.js @@ -29,7 +29,7 @@ function main(conf) { var path = '/' + conf.type + '/' + conf.length; bench.http({ - path: path, + path, connections: conf.c }, function() { w1.destroy(); diff --git a/benchmark/http/create-clientrequest.js b/benchmark/http/create-clientrequest.js index 76134663d00a79..f3caa373e91b5b 100644 --- a/benchmark/http/create-clientrequest.js +++ b/benchmark/http/create-clientrequest.js @@ -13,7 +13,7 @@ function main(conf) { var n = +conf.n; var path = '/'.repeat(pathlen); - var opts = { path: path, createConnection: function() {} }; + var opts = { path, createConnection() {} }; bench.start(); for (var i = 0; i < n; i++) { diff --git a/benchmark/http/simple.js b/benchmark/http/simple.js index 39c8f29dc89a74..87f83011cf2179 100644 --- a/benchmark/http/simple.js +++ b/benchmark/http/simple.js @@ -19,7 +19,7 @@ function main(conf) { conf.res; bench.http({ - path: path, + path, connections: conf.c }, function() { server.close(); diff --git a/benchmark/misc/util-extend-vs-object-assign.js b/benchmark/misc/util-extend-vs-object-assign.js index 41c15d7d2caa0c..a023390c98e1ac 100644 --- a/benchmark/misc/util-extend-vs-object-assign.js +++ b/benchmark/misc/util-extend-vs-object-assign.js @@ -23,7 +23,7 @@ function main(conf) { for (var i = 0; i < conf.type.length * 10; i += 1) fn({}, process.env); - var obj = new Proxy({}, { set: function(a, b, c) { return true; } }); + var obj = new Proxy({}, { set(a, b, c) { return true; } }); bench.start(); for (var j = 0; j < n; j += 1) diff --git a/benchmark/misc/v8-bench.js b/benchmark/misc/v8-bench.js index 85c64b51fda1ef..9271a731a0a8d8 100644 --- a/benchmark/misc/v8-bench.js +++ b/benchmark/misc/v8-bench.js @@ -26,10 +26,10 @@ load('navier-stokes.js'); const benchmark_name = path.join('misc', 'v8-bench.js'); const times = {}; global.BenchmarkSuite.RunSuites({ - NotifyStart: function(name) { + NotifyStart(name) { times[name] = process.hrtime(); }, - NotifyResult: function(name, result) { + NotifyResult(name, result) { const elapsed = process.hrtime(times[name]); common.sendResult({ name: benchmark_name, @@ -40,10 +40,10 @@ global.BenchmarkSuite.RunSuites({ time: elapsed[0] + elapsed[1] / 1e9 }); }, - NotifyError: function(name, error) { + NotifyError(name, error) { console.error(name + ': ' + error); }, - NotifyScore: function(score) { + NotifyScore(score) { common.sendResult({ name: benchmark_name, conf: {