WXL
3 天以前 2cc85c64f1c64a2dbaeae276a3e2ca8420de76b7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { Bench } from 'tinybench'
import { wsIsSecure } from '../lib/schemes.js'
 
const benchWsIsSecure = new Bench({ name: 'wsIsSecure' })
 
const wsComponentAttributeSecureTrue = {
  scheme: 'ws',
  secure: true,
}
 
const wsComponentAttributeSecureFalse = {
  scheme: 'ws',
  secure: false,
}
 
const wssComponent = {
  scheme: 'wss',
}
 
const wssComponentMixedCase = {
  scheme: 'Wss',
}
 
const wssComponentUpperCase = {
  scheme: 'WSS',
}
 
const httpComponent = {
  scheme: 'http',
}
 
console.assert(wsIsSecure(wsComponentAttributeSecureTrue) === true, 'wsComponentAttributeSecureTrue should be secure')
console.assert(wsIsSecure(wsComponentAttributeSecureFalse) === false, 'wsComponentAttributeSecureFalse should not be secure')
console.assert(wsIsSecure(wssComponent) === true, 'wssComponent should be secure')
console.assert(wsIsSecure(wssComponentMixedCase) === true, 'wssComponentMixedCase should be secure')
console.assert(wsIsSecure(wssComponentUpperCase) === true, 'wssComponentUpperCase should be secure')
console.assert(wsIsSecure(httpComponent) === false, 'httpComponent should not be secure')
 
benchWsIsSecure.add(JSON.stringify(wsComponentAttributeSecureFalse), function () {
  wsIsSecure(wsComponentAttributeSecureFalse)
})
 
benchWsIsSecure.add(JSON.stringify(wsComponentAttributeSecureTrue), function () {
  wsIsSecure(wsComponentAttributeSecureTrue)
})
 
benchWsIsSecure.add(JSON.stringify(wssComponent), function () {
  wsIsSecure(wssComponent)
})
 
benchWsIsSecure.add(JSON.stringify(wssComponentMixedCase), function () {
  wsIsSecure(wssComponentMixedCase)
})
 
benchWsIsSecure.add(JSON.stringify(wssComponentUpperCase), function () {
  wsIsSecure(wssComponentUpperCase)
})
 
benchWsIsSecure.add(JSON.stringify(httpComponent), function () {
  wsIsSecure(httpComponent)
})
 
await benchWsIsSecure.run()
console.log(benchWsIsSecure.name)
console.table(benchWsIsSecure.table())