source: frontend/node_modules/fast-uri/benchmark/ws-is-secure.mjs

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

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