SiddiqSoft.TimeThis
2.0.2
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package SiddiqSoft.TimeThis --version 2.0.2
NuGet\Install-Package SiddiqSoft.TimeThis -Version 2.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SiddiqSoft.TimeThis" Version="2.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SiddiqSoft.TimeThis --version 2.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SiddiqSoft.TimeThis, 2.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SiddiqSoft.TimeThis as a Cake Addin #addin nuget:?package=SiddiqSoft.TimeThis&version=2.0.2 // Install SiddiqSoft.TimeThis as a Cake Tool #tool nuget:?package=SiddiqSoft.TimeThis&version=2.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
TimeThis : Simple stopwatch for scope
Objective
Provide for a simple utility class where we can time the operation of a code block and allow the time to be updated in an optional lambda.
auto handleHTTPMessage(auto req)
{
if( req == HTTP_GET )
{
if( req == "/v1/something" )
{
// Consider the scenario where we would like to inform
// the client time taken.
auto resp= createResponse();
// Declaration of the lambda takes the resp object
// and sets the header and logs to our global logger
TimeThis tt{ [&g_logger,&resp](const auto& delta) {
// Get the time in milliseconds..
auto ttx= std::chrono::duration_cast<milliseconds>(tt.elapsed());
// Set the diagnostic header
resp->addHeader("X-Diagnostic-Time", std::to_string(ttx.count()) );
// Log this response
g_logger->debug("Processing /v1/something took {}ms", ttx );
}
}; // notes the call function and starts the stopwatch
// Some other work..Perhaps lookup db, etc.
..
..
resp= ...; // set the body
return resp;
}
}
}
- Support formatter for
std::format
when available - Support use of
std::source_location
when available - Simple "api" where all of your work is in your lambda
Usage
Options
Nuget
- Use the nuget SiddiqSoft.TimeThis
Cmake
.
# Fetch the latest or specify the tag..
FetchContent_Declare( timethis
GIT_REPOSITORY https://github.com/siddiqsoft/TimeThis.git
GIT_SHALLOW 1)
FetchContent_MakeAvailable(timethis)
.
.
target_link_libraries(${PROJECT_NAME} timethis)
You may then use timethis
by adding #include "siddiqsoft/timethis.hpp
in your client code.
Source Examples
#include "gtest/gtest.h"
#include "siddiqsoft/timethis.hpp"
TEST(examples, Example1)
{
bool passTest {false};
try
{
// Use initializer list-style instantiation; we do not allow move/assignment construction.
// Note that the `()` is not required when the lambda/function takes no argument.
siddiqsoft::TimeThis tt {[&passTest] {
// Runs when this scope ends
passTest = true;
}};
auto timeTaken= tt.elapsed();
}
catch (...) {
EXPECT_TRUE(false); // if we throw then the test fails.
}
// Iff the lambda runs, it should be true
EXPECT_TRUE(passTest);
}
Notes
- Supported prefix:
Darwin
Linux
Windows
<small align="right">
© 2021 Siddiq Software LLC. All rights reserved.
</small>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
native | native is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on SiddiqSoft.TimeThis:
Package | Downloads |
---|---|
SiddiqSoft.CosmosClient
Azure Cosmos REST-API Client for Modern C++ |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.1.2 | 73 | 11/14/2024 |
2.1.1 | 70 | 11/8/2024 |
2.0.2 | 75 | 11/5/2024 |
2.0.1 | 71 | 11/5/2024 |
2.0.0 | 73 | 11/5/2024 |
1.3.1 | 76 | 11/5/2024 |
1.3.0 | 92 | 10/30/2024 |
1.2.1 | 75 | 10/30/2024 |
1.1.5 | 710 | 11/20/2021 |
1.1.4 | 327 | 7/30/2021 |
1.1.3 | 308 | 7/28/2021 |
1.1.2 | 358 | 7/28/2021 |
1.1.1 | 350 | 7/28/2021 |
1.1.0 | 9,085 | 7/28/2021 |
1.0.1 | 8,557 | 7/28/2021 |