summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorsurya panikkal <surya.com@gmail.com>2016-06-09 22:10:10 -0400
committerJames M Snell <jasnell@gmail.com>2016-06-27 08:32:08 -0700
commit6abb06f821ba1e9e8646094bab56d93df3704ab5 (patch)
tree45a5156750efa16ed938e17d44e0f626bc10e9f0 /benchmark
parent3c09d1b55f610573d25c21a157546d18b6fcd299 (diff)
downloadandroid-node-v8-6abb06f821ba1e9e8646094bab56d93df3704ab5.tar.gz
android-node-v8-6abb06f821ba1e9e8646094bab56d93df3704ab5.tar.bz2
android-node-v8-6abb06f821ba1e9e8646094bab56d93df3704ab5.zip
benchmark: `util._extend` vs `object.assign`
To copy the values of all enumerable own properties from- a source object to a target object, node still use- `util._extend`, though newer standard `Object.assign` is available. This is because `util._extend` is found to be faster than `Object.assign`. This benchmark test is to keep track of how performance compare. PR-URL: https://github.com/nodejs/node/pull/7255 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/misc/util-extend-vs-object-assign.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/benchmark/misc/util-extend-vs-object-assign.js b/benchmark/misc/util-extend-vs-object-assign.js
new file mode 100644
index 0000000000..caea42ce91
--- /dev/null
+++ b/benchmark/misc/util-extend-vs-object-assign.js
@@ -0,0 +1,40 @@
+'use strict';
+
+const common = require('../common.js');
+const util = require('util');
+const v8 = require('v8');
+
+const bench = common.createBenchmark(main, {
+ type: ['extend', 'assign'],
+ n: [10e4]
+});
+
+function main(conf) {
+ let fn;
+ const n = conf.n | 0;
+ let v8command;
+
+ if (conf.type === 'extend') {
+ fn = util._extend;
+ v8command = '%OptimizeFunctionOnNextCall(util._extend)';
+ } else if (conf.type === 'assign') {
+ fn = Object.assign;
+ // Object.assign is built-in, cannot be optimized
+ v8command = '';
+ }
+
+ // Force-optimize the method to test so that the benchmark doesn't
+ // get disrupted by the optimizer kicking in halfway through.
+ for (var i = 0; i < conf.type.length * 10; i += 1)
+ fn({}, process.env);
+
+ v8.setFlagsFromString('--allow_natives_syntax');
+ eval(v8command);
+
+ var obj = new Proxy({}, { set: function(a, b, c) { return true; } });
+
+ bench.start();
+ for (var j = 0; j < n; j += 1)
+ fn(obj, process.env);
+ bench.end(n);
+}