We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
essentially
#include <string_view> #include <cstdint> #include <iostream> #include <vector> #include <thread> #include <chrono> #define PRINT(...) std::cout << __FILE__ << " " << __LINE__ << " " << __VA_ARGS__ << std::endl; std::uint64_t now() { return std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::system_clock::now().time_since_epoch()) .count(); } struct Report; static std::vector<Report*> reports; struct Report { std::string_view s; std::uint32_t l = 0; Report(std::string_view const& sv, std::uint32_t const& _l) : s{sv}, l{_l} { reports.emplace_back(this); } std::vector<std::uint32_t> times; }; struct scope_timer { Report& r; std::uint64_t const start = now(); ~scope_timer() noexcept { r.times.emplace_back(now() - start); } }; #define SCOPE_TIMER \ static Report ridx_##__LINE__{__FILE__, __LINE__}; \ scope_timer _scope_timer_##__LINE__{ridx_##__LINE__}; void fn0() { SCOPE_TIMER; using namespace std::chrono_literals; std::this_thread::sleep_for(100ms); } void fn1() { SCOPE_TIMER; using namespace std::chrono_literals; std::this_thread::sleep_for(100ms); fn0(); } int main() { for (std::size_t i = 0; i < 5; ++i) fn1(); for (auto const& rp : reports) { auto const& r = *rp; PRINT(r.s << " " << r.l); for (auto const& t : r.times) PRINT(t); } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
essentially
The text was updated successfully, but these errors were encountered: