Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <chrono>
- #include <iostream>
- static unsigned long long total = 0;
- __attribute__((__noinline__)) void by_ref(const std::chrono::system_clock::time_point& t)
- {
- total += (std::chrono::system_clock::now() - t).count();
- }
- __attribute__((__noinline__)) void by_value(std::chrono::system_clock::time_point t)
- {
- total += (std::chrono::system_clock::now() - t).count();
- }
- int main(void)
- {
- std::chrono::system_clock::time_point t = std::chrono::system_clock::now();
- std::cout << "size: " << sizeof(t) << std::endl;
- const unsigned long long tries = 10000000;
- auto before = std::chrono::high_resolution_clock::now();
- for (unsigned long long i = 0; i < tries; ++i)
- by_ref(t);
- auto diff = std::chrono::high_resolution_clock::now() - before;
- std::cout << "by_ref: " << diff.count() << std::endl;
- before = std::chrono::high_resolution_clock::now();
- for (unsigned long long i = 0; i < tries; ++i)
- by_value(t);
- diff = std::chrono::high_resolution_clock::now() - before;
- std::cout << "by_value: " << diff.count() << std::endl;
- std::cout << "total: " << total << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement