Skip to content

Instantly share code, notes, and snippets.

@bagder
Last active November 17, 2023 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bagder/115277dd2873bc3bdd75a1522846884a to your computer and use it in GitHub Desktop.
Save bagder/115277dd2873bc3bdd75a1522846884a to your computer and use it in GitHub Desktop.
URL parsers compared. libcurl vs ada

Compare

Generate URLs to parse

urlgen: https://gist.github.com/bagder/50ca185c73a9d4d38a1d21271f7f2d59

I made 100000 URLs with it:

./urlgen.pl 100000 > URLs

Let libcurl parse them all

speedparse.c: https://gist.github.com/bagder/f61dd7a9a0f568851b94fb8f75cdd26c

Built to use the default Debian libcurl. (8.4.0)

gcc -O3 speedparse.c -lcurl

./a.out Loaded 100002 URLs from URLs 10000200 URLs in 6.85853 secs, 685.8 ns/URL, 1458067.332 URLs/sec

Let ada parse them all

speedada.c: https://gist.github.com/bagder/8efdcaf1244970887ba84bcf734637ba

curl -LO https://github.com/ada-url/ada/releases/download/v2.7.3/ada.cpp
curl -LO https://github.com/ada-url/ada/releases/download/v2.7.3/ada.h

g++ -O3 speedada.c

./a.out Loaded 100002 URLs from URLs 10000200 URLs in 5.43938 secs, 543.9 ns/URL, 1838482.606 URLs/sec

Diff

Without verifying the results of any of the parsers, Ada is 6.85853/5.43938 = 1.2609 times faster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment