Created
September 7, 2017 09:41
-
-
Save whs/aff3da7637ac2af7c3b4fd77bcfd84f2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const dns = require('dns'); | |
| const util = require('util'); | |
| const lookup = util.promisify(dns.lookup); | |
| let timeStart = new Date().getTime(); | |
| let times = 0; | |
| let minTime = Infinity; | |
| let maxTime = 0; | |
| let error = 0; | |
| function bench(){ | |
| let roundStart = new Date().getTime(); | |
| lookup('www.wongnai.com').catch(() => { | |
| error++; | |
| }).then(() => { | |
| let duration = new Date().getTime() - roundStart; | |
| if(duration < minTime){ | |
| minTime = duration; | |
| } | |
| if(duration > maxTime){ | |
| maxTime = duration; | |
| } | |
| times++; | |
| return bench(); | |
| }); | |
| } | |
| function main(){ | |
| bench(); | |
| setInterval(() => { | |
| let runTime = Math.floor((new Date().getTime() - timeStart)/1000); | |
| console.log('Statistics:'); | |
| console.log(`Running time: ${runTime}s`); | |
| console.log(`Qps: ${times/runTime}`); | |
| console.log(`Done: ${times}, Success: ${times-error} (${((times-error)/times)*100}%), Failed: ${error} (${(error/times)*100}%)`); | |
| console.log(`Max query time: ${maxTime}ms, min ${minTime}ms`); | |
| console.log('\n'); | |
| }, 5000); | |
| } | |
| main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment