Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <vector>
- #include <fstream>
- #include <iostream>
- #include <benchmark/benchmark.h>
- /*
- static int s_AllocCount = 0;
- void* operator new(size_t size) {
- s_AllocCount += 1;
- std::cout << "Allocating " << size << " bytes\n";
- return malloc(size);
- }*/
- static std::string readFile(const std::string& filename) {
- // Todo: needs better error handling
- std::ifstream ifs(filename.c_str(), std::ios::in | std::ios::binary | std::ios::ate);
- std::ifstream::pos_type fileSize = ifs.tellg();
- if (fileSize < 0) return std::string{};
- ifs.seekg(0, std::ios::beg);
- std::vector<char> bytes(fileSize);
- ifs.read(&bytes[0], fileSize);
- return std::string(&bytes[0], fileSize);
- }
- void SomeFunction() {
- auto source_text = readFile("Test Programs\\Bank Account\\one_m.inq");
- //std::cout << source_text.length() << '\n';
- // std::cout << s_AllocCount << " allocations\n";
- return;
- }
- static void BM_SomeFunction(benchmark::State& state) {
- // Perform setup here
- for (auto _ : state) {
- // This code gets timed
- SomeFunction();
- }
- }
- // Register the function as a benchmark
- BENCHMARK(BM_SomeFunction);
- // Run the benchmark
- BENCHMARK_MAIN();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement