benchmark.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "norwegian.h++"
  2. #include <chrono>
  3. #include <boost/format.hpp>
  4. #include <iostream>
  5. int main() {
  6. std::vector<integer> numbers;
  7. integer n = 2;
  8. for (int i = 0; i < 256; ++i) {
  9. numbers.push_back(n);
  10. n *= 10;
  11. }
  12. std::vector<std::string> encoded;
  13. using namespace Norwegian;
  14. std::shared_ptr<DFA<char>> dfa1 = makeDFAfromRegEx("(0|abcdefghijklmnopqrstuvwxyz)*");
  15. std::shared_ptr<IStringCodec> codec = std::make_shared<DFAStringCodec>(dfa1);
  16. int i = 0;
  17. for (auto it = numbers.begin(); it != numbers.end(); ++it, ++i) {
  18. // for (auto it = numbers.rbegin(); it != numbers.rend(); ++it) {
  19. const auto n = *it;
  20. auto startenc = std::chrono::steady_clock::now();
  21. encoded.emplace_back(codec->encode(n));
  22. auto stopenc = std::chrono::steady_clock::now();
  23. auto startdec = std::chrono::steady_clock::now();
  24. codec->decode(encoded.back());
  25. auto stopdec = std::chrono::steady_clock::now();
  26. auto diffenc = stopenc - startenc;
  27. auto diffdec = stopdec - startdec;
  28. std::cout << boost::format("%d | %d | %d") % i % std::chrono::duration<double, std::milli>(diffenc).count() % std::chrono::duration<double, std::milli>(diffdec).count() << std::endl << std::flush;
  29. }
  30. return 0;
  31. }