Go vs. C++ – Which is faster?
sukeesh.com
Go vs. C++ – Which is faster?
1–3 of 3 posts
Re: Go vs. C++ – Which is faster?
#2Likely explanation: using a byte for every flag takes a bit less CPU than packing 8 flags in a byte, but once the array outgrows the CPU’s cache, cache misses dominate running time.
Prediction: use std::bitset instead of an array of bool in the C++ code, and performance of the two programs will be (almost) identical.
Re: Go vs. C++ – Which is faster?
#3Likely explanation: using a byte for every flag takes a bit less CPU than packing 8 flags in a byte, but once the array outgrows the CPU’s cache, cache misses dominate running time. Prediction: use std::bitset instead of an array of bool in the C++ code, and performance of the two programs will be (almost) identical.
Could be even simpler than that. I want to know how it was compiled.
I have a 2.3 GHz Intel Core i5 MacBook Pro, which is slower than the given hardware. The linked-to page reports "0.05s user".
I can reproduce that using g++ 9.1.0 using the default optimizations:
% g++-9 sieve.cc
% time ./a.out 4194304
0.056u 0.003s 0:00.06 83.3% 0+0k 0+0io 99pf+0w
If I recompile with -O3, the result is significantly faster: % g++-9 -O3 sieve.cc
% time ./a.out 4194304
0.001u 0.003s 0:00.00 0.0% 0+0k 0+0io 98pf+0w