Architecture | Ubuntu | macOS | Windows |
---|---|---|---|
x86_64 | |||
ARM | |||
RISCV |
TimeIt is a lightweight C++
library designed to provide low-overhead timing functionality for your projects. Whether you need to measure the execution time of a specific function or profile an entire project, TimeIt makes it easy and efficient. This README provides an overview of TimeIt, its features, and instructions for integrating it into your C++ projects.
- Simple and easy-to-use API for measuring execution time.
- Minimal overhead to ensure accurate timing results.
- Ability to time both functions and entire projects.
- Support for various time units (seconds, milliseconds, microseconds, etc.).
- Compatibility with
C++20
and above. - Cross-platform support for
Windows
,Linux
, andmacOS
.
- CMake (Version 3.5 or higher)
- C++ Compiler (
C++20
or higher)
To integrate TimeIt
into your C++
project, follow these steps:
- Clone the
TimeIt
repository to your local machine:
git clone https://github.com/mjshakir/TimeIt.git
- Create a build directory and navigate to it:
cd TimeIt
mkdir build
cd build
- Configure the build with CMake, specifying any desired options (e.g., colored output and build type):
cmake -DFORCE_COLORED_OUTPUT=ON -DCMAKE_BUILD_TYPE=Release ..
- Build TimeIt using your chosen build system (e.g.,
Ninja
):
cmake --build .
- (Optional) Install TimeIt globally on your system:
sudo cmake --install .
- Install
Ninja
(if not already installed) as a build system:
- Linux (Debian based):
sudo apt-get install ninja-build -y
- macOS:
brew install ninja
- Windows:
choco install ninja
- Clone the
TimeIt
repository to your local machine:
git clone https://github.com/your_username/TimeIt.git
cd TimeIt
- Configure the build with CMake, specifying any desired options (e.g., colored output and build type):
cmake -DFORCE_COLORED_OUTPUT=ON -DCMAKE_BUILD_TYPE=Release -B build -G Ninja
- Build TimeIt using your chosen build
Ninja
system:
cd build
ninja
- (Optional) preform test:
ninja test
If you want to include the TimeIt library as a Git submodule in your project, follow these steps:
-Step 1: Add TimeIt as a Git Submodule
In your project's repository, navigate to the directory where you want to add TimeIt as a submodule and run the following command:
git submodule add https://github.com/mjshakir/TimeIt.git extern/TimeIt
- Step 2: Update Your Project's CMakeLists.txt
In your project's CMakeLists.txt, configure the TimeIt submodule and link it to your project. Here's an example:
# Include the TimeIt submodule
add_subdirectory(thirdparty/TimeIt)
# Add your project's source files
# Create an executable or library for your project
add_executable(your_project ${YOUR_SOURCE_FILES})
# Link your project with TimeIt
target_link_libraries(your_project PRIVATE TimeIt::TimeIt)
- Step 3: Build Your Project
Now, when you build your project, CMake will automatically build TimeIt as part of your project's build process because it's included as a submodule.
TimeIt provides two main classes: TimeIt
and TimeFunction
, allowing you to time functions and projects easily.
#include "TimeIt.hpp"
int main() {
// Start timing the entire project
TimeIt::TimeIt timer("MyProject");
// Your project code here
// Get the execution time in seconds
double executionTime = timer.get_time();
std::cout << "Project Execution Time: " << executionTime << " seconds" << std::endl;
return 0;
}
#include "TimeFunction.hpp"
int MyFunction(int a, int b) {
return a*b;
}
int main() {
// Timing a function and obtaining the execution time in seconds
double executionTime = TimeIt::TimeFunction::timed_Function(MyFunction, 10, 20);
std::cout << "Execution Time: " << executionTime << " seconds" << std::endl;
return 0;
}
We welcome contributions to ThreadPool! Whether you're a seasoned developer or just starting out, there are many ways to contribute to this project.
-
Reporting bugs or problems: If you encounter any bugs or issues, please open an issue in the GitHub repository. We appreciate detailed reports that help us understand the cause of the problem.
-
Suggesting enhancements: Do you have ideas for making ThreadPool even better? We'd love to hear your suggestions. Please create an issue to discuss your ideas.
-
Code contributions: Want to get hands-on with the code? Great! Please feel free to fork the repository and submit your pull requests. Whether it's bug fixes, new features, or improvements to documentation, all contributions are greatly appreciated.
- Fork the repository and create your branch from main.
- If you've added or changed code, please ensure the testing suite passes. Add new tests for new features or bug fixes.
- Ensure your code follows the existing style to keep the codebase consistent and readable.
- Include detailed comments in your code so others can understand your changes.
- Write a descriptive commit message.
- Push your branch to GitHub and submit a pull request.