|
| 1 | +import { Bench } from 'tinybench' |
| 2 | +import { fastUri } from '../index.js' |
| 3 | + |
| 4 | +const { |
| 5 | + equal: fastUriEqual, |
| 6 | + parse: fastUriParse, |
| 7 | +} = fastUri |
| 8 | + |
| 9 | +const stringA = 'example://a/b/c/%7Bfoo%7D' |
| 10 | +const stringB = 'eXAMPLE://a/./b/../b/%63/%7bfoo%7d' |
| 11 | + |
| 12 | +const componentA = fastUriParse(stringA) |
| 13 | +const componentB = fastUriParse(stringB) |
| 14 | + |
| 15 | +const benchFastUri = new Bench({ name: 'fast-uri equal' }) |
| 16 | + |
| 17 | +benchFastUri.add('equal string with string', function () { |
| 18 | + fastUriEqual(stringA, stringA) |
| 19 | +}) |
| 20 | + |
| 21 | +benchFastUri.add('equal component with component', function () { |
| 22 | + fastUriEqual(componentA, componentA) |
| 23 | +}) |
| 24 | + |
| 25 | +benchFastUri.add('equal component with string', function () { |
| 26 | + fastUriEqual(componentA, stringA) |
| 27 | +}) |
| 28 | + |
| 29 | +benchFastUri.add('equal string with component', function () { |
| 30 | + fastUriEqual(stringA, componentA) |
| 31 | +}) |
| 32 | + |
| 33 | +benchFastUri.add('not equal string with string', function () { |
| 34 | + fastUriEqual(stringA, stringB) |
| 35 | +}) |
| 36 | + |
| 37 | +benchFastUri.add('not equal component with component', function () { |
| 38 | + fastUriEqual(componentA, componentB) |
| 39 | +}) |
| 40 | + |
| 41 | +benchFastUri.add('not equal component with string', function () { |
| 42 | + fastUriEqual(componentA, stringB) |
| 43 | +}) |
| 44 | + |
| 45 | +benchFastUri.add('not equal string with component', function () { |
| 46 | + fastUriEqual(stringA, componentB) |
| 47 | +}) |
| 48 | + |
| 49 | +await benchFastUri.run() |
| 50 | +console.log(benchFastUri.name) |
| 51 | +console.table(benchFastUri.table()) |
0 commit comments