Skip to content

Instantly share code, notes, and snippets.

@yyx990803
Last active March 23, 2018 08:12
Show Gist options
  • Save yyx990803/196b828f370faa4b6edb6ccb443cb64f to your computer and use it in GitHub Desktop.
Save yyx990803/196b828f370faa4b6edb6ccb443cb64f to your computer and use it in GitHub Desktop.
const { URL } = require('url')
const https = require('https')
const pingCount = 5
const paths = {
npm: `https://registry.npmjs.org/vue/latest`,
yarn: `https://registry.yarnpkg.com/vue/latest`,
tb: `https://registry.npm.taobao.org/vue/latest`
}
const ping = url => {
return new Promise((resolve, reject) => {
const start = Date.now()
const { hostname, pathname } = new URL(url)
const req = https.request({
hostname,
path: pathname
}, () => {
process.stdout.write('.')
resolve(Date.now() - start)
})
req.on('error', reject)
req.end()
})
}
const pingX = (registry, times) => {
return ping(paths[registry]).then(latency => {
return times > 1
? pingX(registry, times - 1).then(results => [latency, ...results])
: [latency]
})
}
const pings = Object.keys(paths).map(registry => {
return pingX(registry, pingCount).then(results => ({
registry,
results
}))
})
Promise.all(pings)
.then(results => {
console.log()
console.log(results)
})
.catch(err => {
console.log(err)
})
@huangang
Copy link

huangang commented Jan 3, 2018

[ { registry: 'npm', results: [ 3153, 1498, 856, 821, 601 ] },
  { registry: 'yarn', results: [ 2623, 2866, 1907, 921, 750 ] },
  { registry: 'tb', results: [ 88, 46, 40, 41, 41 ] } ]

浙江杭州

@Erichain
Copy link

Erichain commented Jan 3, 2018

四川成都

1、开代理

[ { registry: 'npm', results: [ 5488, 811, 1973, 1098, 1536 ] },
  { registry: 'yarn', results: [ 1683, 855, 779, 921, 1537 ] },
  { registry: 'tb', results: [ 207, 161, 165, 165, 155 ] } ]

2、未开代理

[ { registry: 'npm', results: [ 2933, 2873, 2150, 820, 2457 ] },
  { registry: 'yarn', results: [ 972, 968, 720, 879, 819 ] },
  { registry: 'tb', results: [ 213, 153, 176, 164, 279 ] } ]

Node Version: node v9.0.0

@marvinemao
Copy link

image

[ { registry: 'npm', results: [ 2233, 1721, 1691, 1563, 695 ] },
  { registry: 'yarn', results: [ 1040, 756, 9771, 768, 840 ] }, 
  { registry: 'tb', results: [ 204, 148, 156, 141, 138 ] } ]    

四川成都--电信

@hz2
Copy link

hz2 commented Jan 4, 2018

...............
[ { registry: 'npm', results: [ 2640, 671, 2733, 3893, 4287 ] },
{ registry: 'yarn', results: [ 1335, 1277, 695, 700, 933 ] },
{ registry: 'tb', results: [ 129, 99, 92, 92, 95 ] } ]
武汉电信

@moonou
Copy link

moonou commented Jan 4, 2018

四川成都 电信

[ { registry: 'npm', results: [ 3705, 783, 5505, 726, 737 ] },
  { registry: 'yarn', results: [ 2145, 1829, 1964, 3055, 1865 ] },
  { registry: 'tb', results: [ 353, 256, 177, 254, 521 ] } ]

@lnky79
Copy link

lnky79 commented Jan 4, 2018

港深
image

@kangschampagne
Copy link

kangschampagne commented Jan 4, 2018

福建-厦门-集美 长城宽带
image

[
  { registry: 'npm', results: [ 1423, 231, 260, 226, 257 ] },
  { registry: 'yarn', results: [ 1923, 693, 527, 543, 1679 ] },
  { registry: 'tb', results: [ 1281, 162, 191, 185, 162 ] }
]
[
  { registry: 'npm', results: [ 348, 260, 237, 229, 246] },
  { registry: 'yarn', results: [ 690, 1821, 1513, 677, 591] },
  { registry: 'tb', results: [ 200, 123, 140, 121, 185] }
]

@crazhou
Copy link

crazhou commented Jan 4, 2018

地点:广东,深圳 ,宝安 电信

 { registry: 'npm', results: [ 1888, 981, 925, 963, 940 ] },
 { registry: 'yarn', results: [ 1106, 742, 841, 826, 627 ] },
 { registry: 'tb', results: [ 161, 123, 116, 117, 123 ] } 

@nic611
Copy link

nic611 commented Jan 15, 2018

地点:广东,广州,电信
{ registry: 'npm', results: [ 1336, 161, 156, 161, 161 ] }, { registry: 'yarn', results: [ 1573, 169, 156, 177, 170 ] }, { registry: 'tb', results: [ 169, 103, 104, 104, 107 ] }
image

@jasonwwl
Copy link

地点:陕西,西安,电信

[ 
  { registry: 'npm', results: [ 2477, 1784, 381, 378, 345 ] },
  { registry: 'yarn', results: [ 1232, 514, 526, 745, 577 ] },
  { registry: 'tb', results: [ 1675, 1817, 1733, 2056, 1844 ] } 
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment