Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,900 questions

51,831 answers

573 users

How to measure time in nanoseconds with C++

1 Answer

0 votes
#include <iostream>
#include <chrono>

int main() {
    auto start = std::chrono::high_resolution_clock::now();
    
    if (1)
        std::cout << "True" << '\n';
    
    auto end = std::chrono::high_resolution_clock::now();
    
    auto time_in_nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();
    
    std::cout << time_in_nanoseconds << " [ns]";
}




/*
run:

True
24993 [ns]

*/

 



answered Feb 22, 2022 by avibootz

Related questions

1 answer 62 views
62 views asked Mar 14, 2025 by avibootz
1 answer 241 views
1 answer 75 views
75 views asked Oct 17, 2024 by avibootz
2 answers 102 views
1 answer 155 views
155 views asked Feb 21, 2022 by avibootz
1 answer 293 views
...