jeudi 19 mars 2020

java nanoTime vs C++ nanoseconds

I would like to print the nanotimes from two languages and compare the value.

JAVA code

long nano_startTime = System.nanoTime();
System.out.println(nano_startTime);

C++ code

system_clock::time_point begin = system_clock::now();
auto since_epoch = begin.time_since_epoch(); // get the duration since epoch
std::cout << std::to_string(duration_cast<nanoseconds>(since_epoch).count()) << std::endl;

I expect the results to be equivalent but the results are different...!

Results

JAVA: 4459739378141 
C++   1584649009920663623

BTW: If i use milliseconds the results are equivalent. But I require more precision time data and unfortunately microseconds is not there in java.

Can someone help me? Thanks.

Aucun commentaire:

Enregistrer un commentaire