Why Math Functions in C++ Are So Slow

Written by ryanburn | Published 2020/12/27
Tech Story Tags: c++ | performance | assembly | programming | benchmarks | backend | mathematics | software-development

TLDR Compilers produce code that is significantly slower than what a machine is capable of. Compilers may not be portable even between different x86-64 CPUs. Compiler will optimize the code heavily but will still produce C++ standard compliant code. Compiling the code with C++ -c -O3 -march=native, we get a benchmark benchmark. We’ll use google benchmark to measure how long it takes to compute the square roots of 1,000,000 numbers. Compile with GCC -c:native:compute_sqrt1/1000000 4984457 (4.17, 0.07, 115.05)via the TL;DR App

no story

Written by ryanburn | Mathematical Engineer | Building better models: buildingblock.ai
Published by HackerNoon on 2020/12/27