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)
})
@viablecell
Copy link

[ { registry: 'npm', results: [ 1036, 1754, 866, 862, 1185 ] },
{ registry: 'yarn', results: [ 939, 687, 731, 664, 1218 ] },
{ registry: 'tb', results: [ 102, 57, 60, 53, 58 ] } ]
上海市 电信

@iGarym
Copy link

iGarym commented Jan 3, 2018

[
  { registry: 'npm', results: [ 1985, 640, 580, 599, 915 ] },
  { registry: 'yarn', results: [ 893, 816, 1042, 653, 668 ] },
  { registry: 'tb', results: [ 165, 119, 137, 120, 111 ] }
]

地点:深圳南山区高新园

@ys211
Copy link

ys211 commented Jan 3, 2018

福建厦门:
node ping.js
...............
[ { registry: 'npm', results: [ 1456, 643, 640, 652, 594 ] },
{ registry: 'yarn', results: [ 1246, 650, 616, 630, 595 ] },
{ registry: 'tb', results: [ 136, 87, 86, 82, 83 ] } ]

@mcattx
Copy link

mcattx commented Jan 3, 2018

tim 20180103155448

...............
[ { registry: 'npm', results: [ 10811, 621, 656, 623, 638 ] },
  { registry: 'yarn', results: [ 1044, 621, 1352, 786, 622 ] },
  { registry: 'tb', results: [ 201, 125, 134, 102, 138 ] } ]

Node.js 版本为 v8.5.0
位置是: 广东广州

@gaoyichuan
Copy link

gaoyichuan commented Jan 3, 2018

[ { registry: 'npm', results: [ 2146, 558, 556, 572, 564 ] },
  { registry: 'yarn', results: [ 1378, 577, 600, 556, 581 ] },
  { registry: 'tb', results: [ 269, 132, 119, 121, 122 ] } ]

北京市海淀区教育网
Node.js v9.3.0

@LingRay
Copy link

LingRay commented Jan 3, 2018

[ { registry: 'npm', results: [ 1235, 669, 1523, 1276, 1252 ] },
  { registry: 'yarn', results: [ 1061, 630, 574, 823, 834 ] },
  { registry: 'tb', results: [ 318, 115, 132, 119, 119 ] } ]

广东东莞电信
node 9.2.1

@Moudicat
Copy link

Moudicat commented Jan 3, 2018

[ { registry: 'npm', results: [ 837, 249, 261, 254, 255 ] },
  { registry: 'yarn', results: [ 1446, 801, 1122, 1141, 562 ] },
  { registry: 'tb', results: [ 378, 396, 116, 112, 120 ] } ]

北京市 联通

@ting198791
Copy link

[ { registry: 'npm', results: [ 906, 651, 668, 1692, 656 ] },
{ registry: 'yarn', results: [ 1126, 841, 958, 673, 632 ] },
{ registry: 'tb', results: [ 201, 186, 170, 460, 146 ] } ]

广东省湛江市 电信

@mhulu
Copy link

mhulu commented Jan 3, 2018

[ { registry: 'npm', results: [ 656, 756, 1421, 356, 322 ] },
{ registry: 'yarn', results: [ 3240, 1165, 1229, 749, 839 ] },
{ registry: 'tb', results: [ 189, 111, 104, 100, 132 ] } ]

山东青岛联通
Node 8.9.4

@haidao17
Copy link

haidao17 commented Jan 3, 2018

{ registry: 'npm', results: [ 860, 553, 592, 624, 571 ] },
{ registry: 'yarn', results: [ 892, 828, 645, 576, 780 ] },
{ registry: 'tb', results: [ 159, 112, 117, 117, 117 ] } ]

广东广州

@getive
Copy link

getive commented Jan 3, 2018

ping

[ { registry: 'npm', results: [ 1650, 1247, 643, 641, 651 ] },
{ registry: 'yarn', results: [ 1286, 703, 850, 837, 664 ] },
{ registry: 'tb', results: [ 196, 126, 82, 88, 84 ] } ]

湖南 娄底 电信

@DensonWEI
Copy link

[ { registry: 'npm', results: [ 928, 252, 259, 237, 238 ] },
{ registry: 'yarn', results: [ 1519, 962, 703, 699, 909 ] },
{ registry: 'tb', results: [ 175, 118, 134, 118, 126 ] } ]
坐标北京海淀
Node v8.4.0

@zsxsoft
Copy link

zsxsoft commented Jan 3, 2018

[ { registry: 'npm', results: [ 1328, 390, 392, 429, 399 ] },
  { registry: 'yarn', results: [ 1579, 677, 624, 858, 614 ] },
  { registry: 'tb', results: [ 182, 134, 142, 123, 134 ] } ]
[ { registry: 'npm', results: [ 315, 219, 217, 227, 211 ] },
  { registry: 'yarn', results: [ 976, 593, 804, 817, 825 ] },
  { registry: 'tb', results: [ 133, 82, 85, 81, 82 ] } ]

福建 - 福州大学 - 联通 (跑了两趟)

@HustLiuCN
Copy link

[ { registry: 'npm', results: [ 500, 253, 265, 265, 258 ] },
{ registry: 'yarn', results: [ 1159, 1106, 1230, 1180, 1487 ] },
{ registry: 'tb', results: [ 198, 132, 154, 128, 132 ] } ]

西二旗

@mrtanweijie
Copy link

[ { registry: 'npm', results: [ 958, 609, 609, 843, 643 ] },
  { registry: 'yarn', results: [ 1125, 600, 601, 642, 625 ] },
  { registry: 'tb', results: [ 171, 132, 209, 134, 131 ] } ]
[ { registry: 'npm', results: [ 915, 655, 699, 691, 655 ] },
  { registry: 'yarn', results: [ 876, 615, 1501, 677, 1043 ] },
  { registry: 'tb', results: [ 313, 278, 178, 173, 152 ] } ]

坐标:深圳-南山
Node v8.9.1

@XGHeaven
Copy link

XGHeaven commented Jan 3, 2018

[ { registry: 'npm', results: [ 1268, 12061, 1002, 1193, 7310 ] },
  { registry: 'yarn', results: [ 1008, 822, 1232, 913, 1227 ] },
  { registry: 'tb', results: [ 231, 197, 202, 313, 279 ] } ]

地点浙江杭州,公司的网络,无线设备。

@bouquetrender
Copy link

[ { registry: 'npm', results: [ 1068, 1181, 613, 604, 619 ] },
{ registry: 'yarn', results: [ 999, 821, 856, 911, 581 ] },
{ registry: 'tb', results: [ 169, 106, 113, 118, 108 ] } ]

深圳宝安

@mu-yu
Copy link

mu-yu commented Jan 3, 2018

node ping.js
...............
[ { registry: 'npm', results: [ 989, 271, 278, 249, 249 ] },
  { registry: 'yarn', results: [ 996, 124, 117, 111, 117 ] },
  { registry: 'tb', results: [ 40, 35, 26, 27, 26 ] } ]

浙江杭州

@Clovin
Copy link

Clovin commented Jan 3, 2018

[ { registry: 'npm', results: [ 1574, 569, 631, 597, 592 ] },
  { registry: 'yarn', results: [ 1250, 854, 891, 920, 1720 ] },
  { registry: 'tb', results: [ 170, 122, 118, 104, 108 ] } ]

广东中山 -- 中国电信

Copy link

ghost commented Jan 3, 2018

[ { registry: 'npm', results: [ 4901, 2117, 957, 1724, 5073 ] },
{ registry: 'yarn', results: [ 4688, 887, 878, 855, 1930 ] },
{ registry: 'tb', results: [ 96, 79, 63, 75, 62 ] } ]

上海 长城宽带 node v8.6.0

@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