将其设置为const regex = /^(?:(?:1[0-7]|[0-9])?[0-9]{5}|1800000)$/;
const mustFailTests = [
'9999',
'15',
'1800001',
'9000000',
'0',
'',
];
const mustWorkTests = [
'10000',
'1800000',
'200000',
'25018',
'778410',
'1000000',
'1205900',
];
const start = Date.now();
mustFailTests.forEach((x) => {
const ret = regex.test(x);
console.log(`${x} must fail : result ${ret}`);
});
console.log('--------------------------------');
mustWorkTests.forEach((x) => {
const ret = regex.test(x);
console.log(`${x} must succeed : result ${ret}`);
});
for (let i = 0; i < 500000; i += 1) {
mustWorkTests.forEach(x => regex.test(x));
mustFailTests.forEach(x => regex.test(x));
}
console.log(`It took ${Date.now() - start} ms`);,这是您要连接的主机。您不需要包括端口。请注意,您将需要在生产中使用证书。