bench script is ready and bench test passed
This commit is contained in:
parent
d35a7b9120
commit
008bbbe4d7
|
|
@ -169,16 +169,29 @@ try {
|
||||||
|
|
||||||
# bench 测试
|
# bench 测试
|
||||||
|
|
||||||
可以通过 `` 命令来进行 bench 测试,一方面确保 `xdb` 文件没有错误,一方面可以评估查询性能:
|
可以通过 `node tests/bench.app.js` 命令来进行 bench 测试,一方面确保 `xdb` 文件没有错误,一方面可以评估查询性能:
|
||||||
```bash
|
```bash
|
||||||
|
➜ javascript git:(fr_javascript_ipv6) ✗ node tests/bench.app.js
|
||||||
|
usage: Usage node tests/bench.app.js [command options]
|
||||||
|
|
||||||
|
ip2region bench script
|
||||||
|
|
||||||
|
optional arguments:
|
||||||
|
-h, --help show this help message and exit
|
||||||
|
--db DB ip2region binary xdb file path
|
||||||
|
--src SRC source ip text file path
|
||||||
|
--cache-policy CACHE_POLICY
|
||||||
|
cache policy: file/vectorIndex/content, default: vectorIndex
|
||||||
```
|
```
|
||||||
|
|
||||||
例如:通过默认的 data/ip2region_v4.xdb 和 data/ipv4_source.txt 文件进行 IPv4 的 bench 测试:
|
例如:通过默认的 data/ip2region_v4.xdb 和 data/ipv4_source.txt 文件进行 IPv4 的 bench 测试:
|
||||||
```bash
|
```bash
|
||||||
|
node tests/bench.app.js --db=../../data/ip2region_v4.xdb --src=../../data/ipv4_source.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
例如:通过默认的 data/ip2region_v6.xdb 和 data/ipv6_source.txt 文件进行 IPv6 的 bench 测试:
|
例如:通过默认的 data/ip2region_v6.xdb 和 data/ipv6_source.txt 文件进行 IPv6 的 bench 测试:
|
||||||
```bash
|
```bash
|
||||||
|
node tests/bench.app.js --db=../../data/ip2region_v6.xdb --src=../../data/ipv6_source.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
可以通过分别设置 `cache-policy` 为 file/vectorIndex/content 来测试三种不同缓存实现的效果。
|
可以通过分别设置 `cache-policy` 为 file/vectorIndex/content 来测试三种不同缓存实现的效果。
|
||||||
|
|
|
||||||
|
|
@ -82,9 +82,9 @@ const _split = (line) => {
|
||||||
return ps;
|
return ps;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getMs = () => {
|
const getMillSecs = () => {
|
||||||
const hrTime = process.hrtime();
|
const t = process.hrtime();
|
||||||
return hrTime[0] * 1000000 + hrTime[1] / 1000;
|
return t[0] * 1_000 + t[1] / 1_000_000;
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log(`dbPath=${dbPath}, src=${src}, cachePolicy=${cachePolicy}`);
|
// console.log(`dbPath=${dbPath}, src=${src}, cachePolicy=${cachePolicy}`);
|
||||||
|
|
@ -97,7 +97,7 @@ const main = () => {
|
||||||
const searcher = createSearcher();
|
const searcher = createSearcher();
|
||||||
console.log(`Searcher: ${searcher.toString()}`);
|
console.log(`Searcher: ${searcher.toString()}`);
|
||||||
|
|
||||||
let totalNs = 0, count = 0;
|
let totalMicroSecs = 0, count = 0;
|
||||||
|
|
||||||
// read the source line and do the search bench
|
// read the source line and do the search bench
|
||||||
const rl = readline.createInterface({
|
const rl = readline.createInterface({
|
||||||
|
|
@ -106,7 +106,7 @@ const main = () => {
|
||||||
});
|
});
|
||||||
rl.on('line', async (l) => {
|
rl.on('line', async (l) => {
|
||||||
const ps = _split(l);
|
const ps = _split(l);
|
||||||
const sTime = process.hrtime();
|
const st = process.hrtime();
|
||||||
const sip = xdb.parseIP(ps[0]);
|
const sip = xdb.parseIP(ps[0]);
|
||||||
const eip = xdb.parseIP(ps[1]);
|
const eip = xdb.parseIP(ps[1]);
|
||||||
if (xdb.ipCompare(sip, eip) > 0) {
|
if (xdb.ipCompare(sip, eip) > 0) {
|
||||||
|
|
@ -121,16 +121,18 @@ const main = () => {
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
totalNs += process.hrtime(sTime);
|
|
||||||
|
const diff = process.hrtime(st);
|
||||||
|
totalMicroSecs += (diff[0] * 1_000_1000 + (diff[1] / 1e6));
|
||||||
}).on('error', (err) => {
|
}).on('error', (err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('exit', (code) => {
|
process.on('exit', (code) => {
|
||||||
const tookSec = totalNs / 1e9;
|
const tookSec = totalMicroSecs / 1_000_000;
|
||||||
const _eachUs = count == 0 ? 0 : totalNs / 1e3 / count;
|
const _eachUs = count == 0 ? 0 : totalMicroSecs / count;
|
||||||
console.log(`Bench finished, {cachePolicy: ${cachePolicy}, total: ${count}, took: ${tookSec}s, cost: ${_eachUs} μs/op}`);
|
console.log(`Bench finished, {cachePolicy: ${cachePolicy}, total: ${count}, took: ${tookSec} s, cost: ${_eachUs} µs/op}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue