From d254f4b9c098500c960d9ea4b5d544c34e31bc99 Mon Sep 17 00:00:00 2001 From: harrand Date: Sun, 5 May 2024 01:42:35 +0100 Subject: [PATCH] [cpp] print out timings upon success --- cpp/CMakeLists.txt | 2 ++ cpp/src/psyc_main.cpp | 22 ++++++++++++++++++++++ cpp/src/timer.cpp | 18 ++++++++++++++++++ cpp/src/timer.hpp | 8 ++++++++ 4 files changed, 50 insertions(+) create mode 100644 cpp/src/timer.cpp create mode 100644 cpp/src/timer.hpp diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index e98bfb5..13579a5 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -37,6 +37,8 @@ add_executable(psyc src/lex.cpp src/lex.hpp src/srcloc.hpp + src/timer.cpp + src/timer.hpp src/util.cpp src/util.hpp ) diff --git a/cpp/src/psyc_main.cpp b/cpp/src/psyc_main.cpp index d47045a..3594795 100644 --- a/cpp/src/psyc_main.cpp +++ b/cpp/src/psyc_main.cpp @@ -1,24 +1,46 @@ #include "config.hpp" #include "lex.hpp" +#include "timer.hpp" #include "diag.hpp" #include #include #include +#include config::compiler_args parse_args(std::span cli_args); void print_version_info(); +struct timers +{ + std::uint64_t lexing = 0u; + std::uint64_t parsing = 0u; + std::uint64_t semal = 0u; + std::uint64_t codegen = 0u; + void print() + { + constexpr int width = 16; + std::cout << std::setw(width) << "lexer:" << std::setw(6) << std::setprecision(3) << (this->lexing / 1000.0f) << " seconds" << std::endl; + std::cout << std::setw(width) << "parser:" << std::setw(6) << std::setprecision(3) << (this->parsing / 1000.0f) << " seconds" << std::endl; + std::cout << std::setw(width) << "semal:" << std::setw(6) << std::setprecision(3) << (this->semal / 1000.0f) << " seconds" << std::endl; + std::cout << std::setw(width) << "codegen:" << std::setw(6) << std::setprecision(3) << (this->codegen / 1000.0f) << " seconds" << std::endl; + } +}; + int main(int argc, char** argv) { const std::vector cli_args(argv + 1, argv + argc); config::compiler_args args = parse_args(cli_args); + timers t; + timer::start(); lex::state lex; for(const std::filesystem::path input_file : args.input_files) { lex.tokenised_input_files[input_file] = lex::tokenise(input_file); } + t.lexing = timer::elapsed_millis(); + t.print(); return 0; } diff --git a/cpp/src/timer.cpp b/cpp/src/timer.cpp new file mode 100644 index 0000000..f4f9111 --- /dev/null +++ b/cpp/src/timer.cpp @@ -0,0 +1,18 @@ +#include "timer.hpp" +#include + +namespace timer +{ + std::chrono::time_point now; + + void start() + { + now = std::chrono::system_clock::now(); + } + + std::uint64_t elapsed_millis() + { + auto right_now = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + return right_now - std::chrono::duration_cast(now.time_since_epoch()).count(); + } +} \ No newline at end of file diff --git a/cpp/src/timer.hpp b/cpp/src/timer.hpp new file mode 100644 index 0000000..4e28baa --- /dev/null +++ b/cpp/src/timer.hpp @@ -0,0 +1,8 @@ +#include + +namespace timer +{ + void start(); + + std::uint64_t elapsed_millis(); +} \ No newline at end of file