mirror of
https://github.com/netfun2000/ip2region.git
synced 2026-02-27 09:44:31 +08:00
集成单元测试&覆盖率报告
This commit is contained in:
25
binding/nodejs/tests/benchmark.js
Normal file
25
binding/nodejs/tests/benchmark.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const Benchmark = require('benchmark')
|
||||
const path = require('path')
|
||||
const Searcher = require('..')
|
||||
|
||||
const dbPath = path.join(__dirname, '..', '..', '..', 'data', 'ip2region.xdb')
|
||||
const buffer = Searcher.loadContentFromFile(dbPath)
|
||||
const seacher = Searcher.newWithBuffer(buffer)
|
||||
|
||||
const suite = new Benchmark.Suite()
|
||||
suite
|
||||
.add('#search - 1', async () => {
|
||||
const ip = '202.97.77.50'
|
||||
return seacher.search(ip)
|
||||
})
|
||||
.add('#search - 2', async () => {
|
||||
const ip = '218.4.167.70'
|
||||
return seacher.search(ip)
|
||||
})
|
||||
.on('cycle', function (event) {
|
||||
console.log(String(event.target)) // eslint-disable-line
|
||||
})
|
||||
.on('complete', function () {
|
||||
console.log('Fastest is ' + this.filter('fastest').map('name')) // eslint-disable-line
|
||||
})
|
||||
.run({ async: true })
|
||||
Reference in New Issue
Block a user