File indexing completed on 2026-04-09 07:49:22
0001
0002
0003 #include <chrono>
0004 #include <iostream>
0005 #include <iomanip>
0006
0007 #include "stamp.h"
0008 #include "NP.hh"
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 void test_reverse()
0024 {
0025 std::cout << std::endl << "test_reverse " << std::endl ;
0026 uint64_t t0 = stamp::Now();
0027
0028 using Clock = std::chrono::system_clock;
0029 using Unit = std::chrono::microseconds ;
0030
0031 std::chrono::time_point<Clock> t0_{Unit{t0}} ;
0032 uint64_t t1 = std::chrono::duration_cast<Unit>(t0_.time_since_epoch()).count() ;
0033
0034 std::cout << "t0: " << t0 << std::endl ;
0035 std::cout << "t1: " << t1 << std::endl ;
0036
0037 assert( t0 == t1 ) ;
0038 }
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055 void test_performance()
0056 {
0057 static const int N = 1000000*25 ;
0058 const char* ttpath = "$FOLD/tt.npy" ;
0059
0060 std::cout << std::endl << "test_performance : N " << N << " : save stamps to ttpath " << ttpath << std::endl ;
0061
0062 NP* t = NP::Make<uint64_t>(N) ;
0063 uint64_t* tt = t->values<uint64_t>();
0064 for(int i=0 ; i < N ; i++) tt[i] = stamp::Now();
0065
0066 t->set_meta<std::string>("IDENTITY", U::GetEnv("IDENTITY", "no-IDENTITY") );
0067 t->save(ttpath);
0068 }
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080 void test_format()
0081 {
0082 std::cout << std::endl << "test_format" << std::endl ;
0083 uint64_t t0 = stamp::Now();
0084 std::cout << t0 << " : " << stamp::Format(t0) << " " << stamp::Format() << std::endl ;
0085
0086 std::cout << "stamp::Format() " << stamp::Format() << std::endl;
0087 std::cout << "stamp::Format(stamp::Now()) " << stamp::Format(stamp::Now()) << std::endl;
0088 std::cout << "stamp::Format(0) " << stamp::Format(0) << std::endl;
0089 std::cout << "stamp::Format(1) " << stamp::Format(1) << std::endl;
0090 std::cout << "stamp::Format(1000) " << stamp::Format(1000) << std::endl;
0091 std::cout << "stamp::Format(1000000) " << stamp::Format(1000000) << std::endl;
0092 std::cout << "NOTE TIMEZONE LOCALIZATION OF THE ASSUMED UTC STAMPS" << std::endl ;
0093
0094 for(int i=0 ; i < 10 ; i++)
0095 {
0096 uint64_t t = stamp::Now();
0097 std::cout << std::setw(5) << i << " : " << stamp::Format(t) << std::setw(9) << (t - t0) << std::endl ;
0098 }
0099 }
0100
0101
0102 int main()
0103 {
0104 test_reverse();
0105 test_performance();
0106 test_format();
0107 return 0 ;
0108 }
0109