/main.cpp Secret
Created
May 24, 2023 21:29
bencode.hpp benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <chrono> | |
#include "bencode.hpp" | |
const size_t iteration_count = 5'000'000; | |
bencode::dict gen_bencode_simple_object() { | |
return bencode::dict { | |
{"name", "data"}, | |
{"piece length", 500}, | |
{"pieces", 400}, | |
{"length", 777}, | |
{"dict", bencode::dict { | |
{"a", 4}, | |
{"b", 5}, | |
{"c", 6}, | |
{"d", "e"} | |
}} | |
}; | |
} | |
int main() { | |
auto beg = std::chrono::high_resolution_clock::now(); | |
for (size_t i = 0; i < iteration_count; i++) { | |
auto obj = gen_bencode_simple_object(); | |
bencode::encode(obj).size(); | |
} | |
auto end = std::chrono::high_resolution_clock::now(); | |
std::cout << "Elapsed Time [encode]: " << duration_cast<std::chrono::milliseconds>(end - beg).count() << "ms\n"; | |
// ========================================================= | |
beg = std::chrono::high_resolution_clock::now(); | |
auto encoded = bencode::encode(gen_bencode_simple_object()); | |
for (size_t i = 0; i < iteration_count; i++) { | |
bencode::decode(encoded); | |
} | |
end = std::chrono::high_resolution_clock::now(); | |
std::cout << "Elapsed Time [decode]: " << duration_cast<std::chrono::milliseconds>(end - beg).count() << "ms\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment