C++ chrono

C++ Performance Timer, uses the C++20 language standard

cppreference.com

Date and time utilities
std::chrono::duration
std::formatter
std::put_time

cplusplus.com

Time library
std::chrono::duration

C++ Cross-Platform High-Resolution Timer
chrono_literals is not a namespace-name
How to get duration, as int milli’s and float seconds from ?
Outputting Date and Time in C++ using std::chrono
Print current system time in nanoseconds using c++ chrono
How to convert std::chrono::time_point to string


Old-Style C

Print current system time in nanoseconds using c++ chrono
what is gettimeofday() equivalent in c++11

struct timeval now;

// seconds and nanoseconds
gettimeofday(&now, NULL);
const std::tm *localTime = std::localtime((time_t *) &now.tv_sec);

// only in seconds
//std::time_t now = std::time(nullptr);
//const std::tm *localTime = std::localtime(&now);

// GCC < 5.0
char dateTime[] = "00.00.00 00:00:00.";
char millis [] = "000";
strftime(dateTime, sizeof(dateTime), "%d.%m.%y %H:%M:%S.", localTime);
snprintf(millis, sizeof(millis), "%03li", now.tv_usec/1000 );

cout << dateTime << millis << " | ";


date


SIGSEGV

$ gdb build/bin/PerfTest
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-120.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /app/dev/andreas/build/bin/PerfTest...done.
(gdb) r
Starting program: /app/dev/andreas/build/bin/PerfTest
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6b316a3 in std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /lib64/libstdc++.so.6
Missing separate debuginfos, use: debuginfo-install glibc-2.17-326.el7_9.x86_64 libgcc-4.8.5-44.el7.x86_64 libstdc++-4.8.5-44.el7.x86_64
(gdb) bt
#0  0x00007ffff6b316a3 in std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /lib64/libstdc++.so.6
#1  0x0000000000401751 in app (trx=0x7fffffffe260) at /app/dev/andreas/PerfTest/main.cpp:47
#2  0x00000000004018d1 in main (argc=1, argv=0x7fffffffe398) at /app/dev/andreas/PerfTest/main.cpp:104

Leave a Reply

Your email address will not be published. Required fields are marked *