[ create a new paste ] login | about

Link: http://codepad.org/hXZ9PYK0    [ raw code | fork ]

C++, pasted on Jul 23:
#include <string>

std::array<int, 256>
count_chars(std::string const &str) {
  std::array<int, 256> result;
  for(unsigned char c : str) ++result[c];
  return result;
}

int main() {
  std::ifstream in("README");
  std::ostringstream bucket;

  bucket << in.rdbuf();

  std::string str;

  str.reserve(bucket.str().size() * 100);
  for(int i = 0; i < 100; ++i) { str += bucket.str(); }

  typedef std::chrono::high_resolution_clock clock;

  clock::time_point t0 = clock::now();

  int prevent_optimisation;
  for(int i = 0; i < 5000; ++i) {
    prevent_optimisation += count_chars(str)[0];
  }

  clock::time_point t1 = clock::now();

  std::chrono::milliseconds total_ms(std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0));

  std::cout << "Foo: " << prevent_optimisation << "\n"
            << "Time: " << total_ms.count() << " ms\n";
}


Create a new paste based on this one


Comments: