From c6358117b49660c6c92490061320f0748aef73d9 Mon Sep 17 00:00:00 2001 From: Wu Jian Ping Date: Fri, 22 Jul 2022 13:56:56 +0800 Subject: [PATCH] =?UTF-8?q?bench=E7=A8=8B=E5=BA=8F:=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8D=95=E4=B8=AAIP=E6=AE=B5=EF=BC=8C=E6=A3=80=E6=9F=A55?= =?UTF-8?q?=E4=B8=AAIP=EF=BC=8C=E4=B8=8E=E5=85=B6=E5=AE=83=E8=AF=AD?= =?UTF-8?q?=E8=A8=80=E4=BF=9D=E6=8C=81=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- binding/nodejs/tests/bench.app.js | 42 +++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/binding/nodejs/tests/bench.app.js b/binding/nodejs/tests/bench.app.js index 693dc8e..0a48374 100644 --- a/binding/nodejs/tests/bench.app.js +++ b/binding/nodejs/tests/bench.app.js @@ -82,24 +82,40 @@ const main = async () => { const rl = readline(src) rl .on('line', async (line, lineCount, byteCount) => { - const list = line.split('|') - const sip = list[0] - const eip = list[1] - const sipInt = ipToInt(sip) - const eipInt = ipToInt(eip) + try { + const list = line.split('|') + const sip = list[0] + const eip = list[1] + const sipInt = ipToInt(sip) + const eipInt = ipToInt(eip) - const mipInt = Math.floor((sipInt + eipInt) / 2) - const mip = intToIp(mipInt) + const mipInt = Math.floor((sipInt + eipInt) / 2) + const mip = intToIp(mipInt) - const info = await searcher.search(mip) + const mipLeftInt = Math.floor((sipInt + mipInt) / 2) + const mipLeft = intToIp(mipLeftInt) - const region = list.slice(2, list.length).join('|') - // check the region info - if (region !== info.region) { - console.log(`failed search(${mip}) with (${region} != ${info.region})`) + const mipRightInt = Math.floor((mipInt + eipInt) / 2) + const mipRight = intToIp(mipRightInt) + + const arr = [sip, mipLeft, mip, mipRight, eip] + + for (let i = 0; i < arr.length; ++i) { + const target = arr[i] + const info = await searcher.search(target) + + const region = list.slice(2, list.length).join('|') + // check the region info + if (region !== info.region) { + console.log(`failed search(${mip}) with (${region} != ${info.region})`) + process.exit(1) + } + total++ + } + } catch (err) { + console.log(err) process.exit(1) } - total++ }) .on('error', err => { console.log(err)