-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: improve performance of isIPv4 and isIPv6
PR-URL: #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>
- Loading branch information
1 parent
8aac95d
commit de0a51b
Showing
3 changed files
with
58 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
const common = require('../common.js'); | ||
const { isIPv6 } = require('net'); | ||
|
||
const ips = [ | ||
'::1', | ||
'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', | ||
'0.0.0.0', | ||
]; | ||
|
||
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) | ||
isIPv6(ips[j]); | ||
} | ||
bench.end(n); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters