Some simple code to log your timing of a program in C++
// Timing code using ctime library
// Author: Neville Andrade
typedef std::tuple<int, int> str_int_tuple;
auto colls = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
// Timing code using ctime library
// Author: Neville Andrade
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <tuple>
#include <string>
#include <ctime>
#include <array>
#include <vector>
#include <algorithm>
#include <tuple>
#include <string>
#include <ctime>
typedef std::tuple<int, int> str_int_tuple;
int main()
{
time_t currentTime;
struct tm *localTime;
{
time_t currentTime;
struct tm *localTime;
time(¤tTime);
localTime = localtime(¤tTime); // Convert the current time to the local time
localTime = localtime(¤tTime); // Convert the current time to the local time
int Day = localTime->tm_mday;
int Month = localTime->tm_mon + 1;
int Year = localTime->tm_year + 1900;
int Hour = localTime->tm_hour;
int Min = localTime->tm_min;
int Sec = localTime->tm_sec;
std::cout << "This program was exectued at: " << Hour << ":" << Min << ":" << Sec << std::endl;
std::cout << "And the current date is: " << Day << "/" << Month << "/" << Year << std::endl;
int Month = localTime->tm_mon + 1;
int Year = localTime->tm_year + 1900;
int Hour = localTime->tm_hour;
int Min = localTime->tm_min;
int Sec = localTime->tm_sec;
std::cout << "This program was exectued at: " << Hour << ":" << Min << ":" << Sec << std::endl;
std::cout << "And the current date is: " << Day << "/" << Month << "/" << Year << std::endl;
std::array<int, 10> coll = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
unsigned int myStartTime = static_cast<int>(std::time(0));
unsigned int myStartTime = static_cast<int>(std::time(0));
std::cout << myStartTime << '\n';
auto colls = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
auto result = std::minmax(colls);
//lambda function
auto f2 = [](std::array<int, 10> t)-> str_int_tuple
{
return std::make_tuple(*std::min_element(std::begin(t), std::end(t)), *std::max_element(std::begin(t), std::end(t)));
};
str_int_tuple t = f2(coll);
auto f2 = [](std::array<int, 10> t)-> str_int_tuple
{
return std::make_tuple(*std::min_element(std::begin(t), std::end(t)), *std::max_element(std::begin(t), std::end(t)));
};
str_int_tuple t = f2(coll);
std::cout << std::get<0>(t) << ' ';
std::cout << std::get<1>(t) << '\n';
std::string myString;
std::cin >> myString;
unsigned int myEndTime = static_cast<int>(std::time(0));
std::cout << std::get<1>(t) << '\n';
std::string myString;
std::cin >> myString;
unsigned int myEndTime = static_cast<int>(std::time(0));
std::cout << myEndTime - myStartTime << '\n';
time(¤tTime); // Get the current time
localTime = localtime(¤tTime);
Hour = localTime->tm_hour;
Min = localTime->tm_min;
Sec = localTime->tm_sec;
time(¤tTime); // Get the current time
localTime = localtime(¤tTime);
Hour = localTime->tm_hour;
Min = localTime->tm_min;
Sec = localTime->tm_sec;
std::cout << "This program was exectued at: " << Hour << ":" << Min << ":" << Sec << std::endl;
}
}
Comments
Post a Comment