From 34f3021ca3c5c0439149112a119b761f72089fb3 Mon Sep 17 00:00:00 2001 From: XadillaX Date: Fri, 24 Sep 2021 12:05:39 +0800 Subject: [PATCH] benchmark: add `util.toUSVString()`'s benchmark PR-URL: https://github.com/nodejs/node/pull/40203 Reviewed-By: James M Snell Reviewed-By: Zijian Liu --- benchmark/util/to-usv-string.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 benchmark/util/to-usv-string.js diff --git a/benchmark/util/to-usv-string.js b/benchmark/util/to-usv-string.js new file mode 100644 index 00000000000000..22d23d3198d124 --- /dev/null +++ b/benchmark/util/to-usv-string.js @@ -0,0 +1,21 @@ +'use strict'; + +const common = require('../common'); + +const BASE = 'string\ud801'; + +const bench = common.createBenchmark(main, { + n: [1e5], + size: [10, 100, 500], +}); + +function main({ n, size }) { + const { toUSVString } = require('util'); + const str = BASE.repeat(size); + + bench.start(); + for (let i = 0; i < n; i++) { + toUSVString(str); + } + bench.end(n); +}