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