streams_findbyte.cpp raw

   1  // Copyright (c) 2023 The Limenka developers
   2  // Distributed under the MIT software license, see the accompanying
   3  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
   4  
   5  #include <bench/bench.h>
   6  
   7  #include <streams.h>
   8  #include <util/fs.h>
   9  
  10  #include <cstddef>
  11  #include <cstdint>
  12  #include <cstdio>
  13  
  14  static void FindByte(benchmark::Bench& bench)
  15  {
  16      // Setup
  17      AutoFile file{fsbridge::fopen("streams_tmp", "w+b")};
  18      const size_t file_size = 200;
  19      uint8_t data[file_size] = {0};
  20      data[file_size-1] = 1;
  21      file << data;
  22      file.seek(0, SEEK_SET);
  23      BufferedFile bf{file, /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size};
  24  
  25      bench.run([&] {
  26          bf.SetPos(0);
  27          bf.FindByte(std::byte(1));
  28      });
  29  
  30      // Cleanup
  31      assert(file.fclose() == 0);
  32      fs::remove("streams_tmp");
  33  }
  34  
  35  BENCHMARK(FindByte, benchmark::PriorityLevel::HIGH);
  36