4 ms·
Nice. Did some quick tests with your code on site, got score of ~34000 - best solution is around 14700, so this one is only 2.3 times slower. Used clang with -
by vient 2y ago
Nice. Did some quick tests with your code on site, got score of ~34000 - best solution is around 14700, so this one is only 2.3 times slower.
Used clang with -Ofast -march=native -static. Funnily, gcc gets only 54000 with the same options, 1.6 times slower.
- vient 2y agoWow, changing `count` type from uint64_t to uint32_t or int radically changes results - now gcc gets 26500 and clang gets 25000, that's just 1.7 times slower than current best solution. So you can get 25k with following code, clang -Ofast -std=c++17 -march=native -static #include <iostream> #include <cstdint> #include <sys/mman.h> #include <unistd.h> int main() { auto file_lo = (const uint8_t*)mmap(0,250000000ull,PROT_READ,MAP_PRIVATE|MAP_POPULATE,STDIN_FILENO,0); int count = 0; for (uint32_t i = 0; i < 250000000; ++i) { if (file_lo[i] == 127) { ++count; } } std::cout << count << std::endl; _exit(0); return 0; }
- sYnfo 2y agoNeat! I'll add the best solution without explicit SIMD/asm in this thread to the post after I wake up, it's a great datapoint.