Skip to content

Commit

Permalink
Adds a first IRI validation benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Tpt authored and rubensworks committed Aug 12, 2022
1 parent 25da3ed commit 7e8157d
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 2 deletions.
117 changes: 117 additions & 0 deletions perf/validateIri.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/* eslint-disable no-console */

import { validateIri } from '..';

const ITERATIONS = 100_000;

const VALID_ABSOLUTE_IRIS = [
'file://foo',
'ftp://ftp.is.co.za/rfc/rfc1808.txt',
'http://www.ietf.org/rfc/rfc2396.txt',
'ldap://[2001:db8::7]/c=GB?objectClass?one',
'mailto:[email protected]',
'news:comp.infosystems.www.servers.unix',
'tel:+1-816-555-1212',
'telnet://192.0.2.16:80/',
'urn:oasis:names:specification:docbook:dtd:xml:4.1.2',
'http://example.com',
'http://example.com/',
'http://example.com/foo',
'http://example.com/foo/bar',
'http://example.com/foo/bar/',
'http://example.com/foo/bar?q=1&r=2',
'http://example.com/foo/bar/?q=1&r=2',
'http://example.com#toto',
'http://example.com/#toto',
'http://example.com/foo#toto',
'http://example.com/foo/bar#toto',
'http://example.com/foo/bar/#toto',
'http://example.com/foo/bar?q=1&r=2#toto',
'http://example.com/foo/bar/?q=1&r=2#toto',
'http://example.com/foo/bar/.././baz',
'http://a.example/AZaz\u{00C0}\u{00D6}\u{00D8}\u{00F6}\u{00F8}\u{02FF}\u{0370}\u{037D}\u{037F}\u{1FFF}',
'http://a.example/\u{200C}\u{200D}\u{2070}\u{218F}\u{2C00}\u{2FEF}\u{3001}\u{D7FF}\u{FA0E}\u{FDCF}',
'http://a.example/\u{FDF0}\u{FFEF}\u{10000}\u{EFFFD}',
'http://a.example/?AZaz\u{E000}\u{F8FF}\u{F0000}\u{FFFFD}\u{100000}\u{10FFFD}\u{00C0}\u{00D6}\u{00D8}',
'http://a.example/\u{00F6}\u{00F8}\u{02FF}\u{0370}\u{037D}\u{037F}\u{1FFF}\u{200C}\u{200D}\u{2070}\u{218F}\u{2C00}',
'http://a.example/\u{2FEF}\u{3001}\u{D7FF}\u{FA0E}\u{FDCF}\u{FDF0}\u{FFEF}\u{10000}\u{EFFFD}',
'file:///foo/bar',
'mailto:user@host?subject=blah',
'dav:',
'about:',
'http://www.yahoo.com',
'http://www.yahoo.com/',
'http://1.2.3.4/',
'http://www.yahoo.com/stuff',
'http://www.yahoo.com/stuff/',
'http://www.yahoo.com/hello%20world/',
'http://www.yahoo.com?name=obi',
'http://www.yahoo.com?name=obi+wan&status=jedi',
'http://www.yahoo.com?onery',
'http://www.yahoo.com#bottom',
'http://www.yahoo.com/yelp.html#bottom',
'https://www.yahoo.com/',
'ftp://www.yahoo.com/',
'ftp://www.yahoo.com/hello',
'http://www.yahoo.com?name=%00%01',
'http://www.yaho%6f.com',
'http://www.yahoo.com/hello%00world/',
'http://www.yahoo.com/hello+world/',
'http://www.yahoo.com?name=obi&',
'http://www.yahoo.com?name=obi&type=',
'http://www.yahoo.com/yelp.html#',
'http://example.org/aaa/bbb#ccc',
'mailto:[email protected]',
'mailto:[email protected]#frag',
'HTTP://EXAMPLE.ORG/AAA/BBB#CCC',
'http://example.org/aaa%2fbbb#ccc',
'http://example.org/aaa%2Fbbb#ccc',
'http://example.com/%2F',
'http://example.com/?%2F',
'http://example.com/#?%2F',
'http://example.com/aaa%2Fbbb',
'http://example.org:80/aaa/bbb#ccc',
'http://example.org:/aaa/bbb#ccc',
'http://example.org./aaa/bbb#ccc',
'http://example.123./aaa/bbb#ccc',
'http://example.org',
'http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html',
'http://[1080:0:0:0:8:800:200C:417A]/index.html',
'http://[3ffe:2a00:100:7031::1]',
'http://[1080::8:800:200C:417A]/foo',
'http://[::192.9.5.5]/ipng',
'http://[::FFFF:129.144.52.38]:80/index.html',
'http://[2010:836B:4179::836B:4179]',
'http://example/Andrȷ',
'file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/',
'http://a/?\u{E000}',
'http://example.com/?\u{E000}',
];

const FULL_TIMER = 'Full IRI validation';

console.time(FULL_TIMER);

for (let i = 0; i < ITERATIONS; i++) {
for (const iri of VALID_ABSOLUTE_IRIS) {
validateIri(iri);
}
}

console.timeEnd(FULL_TIMER);

const PARTIAL_TIMER = 'Partial IRI validation';
// eslint-disable-next-line no-control-regex
const PARTIAL_REGEX = /^[a-zA-Z][a-zA-Z0-9+\-.]*:[^\u0000-\u0020"<>\\^`{|}]$/u;

console.time(PARTIAL_TIMER);

for (let i = 0; i < ITERATIONS; i++) {
for (const iri of VALID_ABSOLUTE_IRIS) {
PARTIAL_REGEX.test(iri);
}
}

console.timeEnd(PARTIAL_TIMER);

/* eslint-enable no-console */
3 changes: 2 additions & 1 deletion tsconfig.eslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"index.ts",
"lib/**/*.ts",
"test/**/*.ts",
"bin/**/*.ts"
"bin/**/*.ts",
"perf/**/*.ts"
],
"exclude": [
"**/node_modules"
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
},
"include": [
"index.ts",
"lib/**/*"
"lib/**/*",
"perf/**/*"
],
"exclude": [
"**/node_modules",
Expand Down

0 comments on commit 7e8157d

Please sign in to comment.