Comment

Comment by vient

Wow, 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;
    }
parent vient 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton