equal.mjs 1.3 KB

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