I had a need to parse a huge JSON file, and I was curious how much performance
speed up could be had just checking the first character, and hashing everything
instead of using strcmp.
Full code can be found here
||strcmp with prefix
||hash ahead of time
The platforms tested are
Linux Ubuntu 18 - Intel(R) Core(TM) i7-8550U CPU @ 1.8GHz
gcc bench_strcmp.c -O3 (GCC 7.3.0)
MacOSX 10.14 - Intel(R) Core(TM) i5-5257U @ 2.70GHz
clang bench_strcmp.c -O3 (Clang 1000.11.45)
Linux Ubuntu 16 - Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
gcc bench_strcmp.c -DBENCH_TO_RUN=BENCH_ -O3 (GCC 5.4.0)
clang bench_strcmp.c -DBENCH_TO_RUN=BENCH_ -O3 (Clang 7.0.0)
A basic strcpy benchmark, sets the baseline.
Strcpy Prefix Check
Before running strcpy check the first character, as a runtime solution this
is the winner.
Hashing strings and then comparing the hashes, this doesn’t handle collisions.
Ahead Of Time Hashing
Hashing strings upfront. Predictably this is the fastests.