node/benchmark/net/net-is-ip-v4.js
Uzlopak 4e01842943
net: improve performance of isIPv4 and isIPv6
PR-URL: https://github.com/nodejs/node/pull/49568
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-09-13 20:01:36 +00:00

26 lines
414 B
JavaScript

'use strict';
const common = require('../common.js');
const { isIPv4 } = require('net');
const ips = [
'0.0.0.0',
'255.255.255.255',
'0.0.0.0.0',
'192.168.0.1',
'10.168.209.250',
];
const bench = common.createBenchmark(main, {
n: [1e7],
});
function main({ n }) {
bench.start();
for (let i = 0; i < n; ++i) {
for (let j = 0; j < ips.length; ++j)
isIPv4(ips[j]);
}
bench.end(n);
}