forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdeprecate.js
More file actions
36 lines (30 loc) · 735 Bytes
/
deprecate.js
File metadata and controls
36 lines (30 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
const common = require('../common');
const assert = require('assert');
const bench = common.createBenchmark(main, {
n: [1e5],
modifyPrototype: [1, 0],
emitWarningSync: [1, 0],
}, {
flags: ['--expose-internals'],
});
function simpleFunction(x) {
return x * 2 + (new Array(1000)).fill(0).map((_, i) => i).reduce((a, b) => a + b, 0);
}
function main({ n, modifyPrototype, emitWarningSync }) {
const { deprecate } = require('internal/util');
const fn = deprecate(
simpleFunction,
'This function is deprecated',
'DEP0000',
emitWarningSync,
!!modifyPrototype,
);
let sum = 0;
bench.start();
for (let i = 0; i < n; ++i) {
sum += fn(i);
}
bench.end(n);
assert.ok(sum);
}