[79a0317] | 1 | 'use strict'
|
---|
| 2 |
|
---|
| 3 | const benchmark = require('benchmark')
|
---|
| 4 | const suite = new benchmark.Suite()
|
---|
| 5 | const fasturi = require('./')
|
---|
| 6 | const urijs = require('uri-js')
|
---|
| 7 |
|
---|
| 8 | const base = 'uri://a/b/c/d;p?q'
|
---|
| 9 |
|
---|
| 10 | const domain = 'https://example.com/foo#bar$fiz'
|
---|
| 11 | const ipv4 = '//10.10.10.10'
|
---|
| 12 | const ipv6 = '//[2001:db8::7]'
|
---|
| 13 | const urn = 'urn:foo:a123,456'
|
---|
| 14 | const urnuuid = 'urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6'
|
---|
| 15 |
|
---|
| 16 | // Initialization as there is a lot to parse at first
|
---|
| 17 | // eg: regexes
|
---|
| 18 | fasturi.parse(domain)
|
---|
| 19 | urijs.parse(domain)
|
---|
| 20 |
|
---|
| 21 | suite.add('fast-uri: parse domain', function () {
|
---|
| 22 | fasturi.parse(domain)
|
---|
| 23 | })
|
---|
| 24 | suite.add('urijs: parse domain', function () {
|
---|
| 25 | urijs.parse(domain)
|
---|
| 26 | })
|
---|
| 27 | suite.add('WHATWG URL: parse domain', function () {
|
---|
| 28 | // eslint-disable-next-line
|
---|
| 29 | new URL(domain)
|
---|
| 30 | })
|
---|
| 31 | suite.add('fast-uri: parse IPv4', function () {
|
---|
| 32 | fasturi.parse(ipv4)
|
---|
| 33 | })
|
---|
| 34 | suite.add('urijs: parse IPv4', function () {
|
---|
| 35 | urijs.parse(ipv4)
|
---|
| 36 | })
|
---|
| 37 | suite.add('fast-uri: parse IPv6', function () {
|
---|
| 38 | fasturi.parse(ipv6)
|
---|
| 39 | })
|
---|
| 40 | suite.add('urijs: parse IPv6', function () {
|
---|
| 41 | urijs.parse(ipv6)
|
---|
| 42 | })
|
---|
| 43 | suite.add('fast-uri: parse URN', function () {
|
---|
| 44 | fasturi.parse(urn)
|
---|
| 45 | })
|
---|
| 46 | suite.add('urijs: parse URN', function () {
|
---|
| 47 | urijs.parse(urn)
|
---|
| 48 | })
|
---|
| 49 | suite.add('WHATWG URL: parse URN', function () {
|
---|
| 50 | // eslint-disable-next-line
|
---|
| 51 | new URL(urn)
|
---|
| 52 | })
|
---|
| 53 | suite.add('fast-uri: parse URN uuid', function () {
|
---|
| 54 | fasturi.parse(urnuuid)
|
---|
| 55 | })
|
---|
| 56 | suite.add('urijs: parse URN uuid', function () {
|
---|
| 57 | urijs.parse(urnuuid)
|
---|
| 58 | })
|
---|
| 59 | suite.add('fast-uri: serialize uri', function () {
|
---|
| 60 | fasturi.serialize({
|
---|
| 61 | scheme: 'uri',
|
---|
| 62 | userinfo: 'foo:bar',
|
---|
| 63 | host: 'example.com',
|
---|
| 64 | port: 1,
|
---|
| 65 | path: 'path',
|
---|
| 66 | query: 'query',
|
---|
| 67 | fragment: 'fragment'
|
---|
| 68 | })
|
---|
| 69 | })
|
---|
| 70 | suite.add('urijs: serialize uri', function () {
|
---|
| 71 | urijs.serialize({
|
---|
| 72 | scheme: 'uri',
|
---|
| 73 | userinfo: 'foo:bar',
|
---|
| 74 | host: 'example.com',
|
---|
| 75 | port: 1,
|
---|
| 76 | path: 'path',
|
---|
| 77 | query: 'query',
|
---|
| 78 | fragment: 'fragment'
|
---|
| 79 | })
|
---|
| 80 | })
|
---|
| 81 | suite.add('fast-uri: serialize IPv6', function () {
|
---|
| 82 | fasturi.serialize({ host: '2606:2800:220:1:248:1893:25c8:1946' })
|
---|
| 83 | })
|
---|
| 84 | suite.add('urijs: serialize IPv6', function () {
|
---|
| 85 | urijs.serialize({ host: '2606:2800:220:1:248:1893:25c8:1946' })
|
---|
| 86 | })
|
---|
| 87 | suite.add('fast-uri: serialize ws', function () {
|
---|
| 88 | fasturi.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: true })
|
---|
| 89 | })
|
---|
| 90 | suite.add('urijs: serialize ws', function () {
|
---|
| 91 | urijs.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: true })
|
---|
| 92 | })
|
---|
| 93 | suite.add('fast-uri: resolve', function () {
|
---|
| 94 | fasturi.resolve(base, '../../../g')
|
---|
| 95 | })
|
---|
| 96 | suite.add('urijs: resolve', function () {
|
---|
| 97 | urijs.resolve(base, '../../../g')
|
---|
| 98 | })
|
---|
| 99 | suite.on('cycle', cycle)
|
---|
| 100 |
|
---|
| 101 | suite.run()
|
---|
| 102 |
|
---|
| 103 | function cycle (e) {
|
---|
| 104 | console.log(e.target.toString())
|
---|
| 105 | }
|
---|