Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Lucas <evanlucas@me.com>2016-02-22 11:55:42 +0300
committerEvan Lucas <evanlucas@me.com>2016-03-05 02:27:10 +0300
commit735e0df8e4e8f79256b10959110aa35b466e0cb3 (patch)
treefb386f98f33465e7ddfcaceefd1fff66e2866398 /benchmark
parent17924703d68bf8d70f8fba3fb1c3fe3493e8db89 (diff)
benchmark: add util.format benchmark
PR-URL: https://github.com/nodejs/node/pull/5360 Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/util/format.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/benchmark/util/format.js b/benchmark/util/format.js
new file mode 100644
index 00000000000..6a0b6c63dc1
--- /dev/null
+++ b/benchmark/util/format.js
@@ -0,0 +1,40 @@
+'use strict';
+
+const util = require('util');
+const common = require('../common');
+const v8 = require('v8');
+const bench = common.createBenchmark(main, {
+ n: [1e6]
+, type: ['string',
+ 'number',
+ 'object',
+ 'unknown',
+ 'no-replace']
+});
+
+const inputs = {
+ 'string': ['Hello, my name is %s', 'fred'],
+ 'number': ['Hi, I was born in %d', 1942],
+ 'object': ['An error occurred %j', {msg: 'This is an error', code: 'ERR'}],
+ 'unknown': ['hello %a', 'test'],
+ 'no-replace': [1, 2]
+};
+
+function main(conf) {
+ const n = conf.n | 0;
+ const type = conf.type;
+
+ const input = inputs[type];
+
+ v8.setFlagsFromString('--allow_natives_syntax');
+
+ util.format(input[0], input[1]);
+ eval('%OptimizeFunctionOnNextCall(util.format)');
+ util.format(input[0], input[1]);
+
+ bench.start();
+ for (var i = 0; i < n; i++) {
+ util.format(input[0], input[1]);
+ }
+ bench.end(n);
+}