fork download
  1. #include <iostream>
  2. #include <chrono>
  3. #include <math.h>
  4.  
  5.  
  6. int clog(int base, int n) {
  7. return (n > base - 1)
  8. ? 1 + clog(n / base, base)
  9. : 0;
  10. }
  11. int main() {
  12.  
  13. std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
  14. clog(10,1024);
  15. std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
  16. std::cout << "Time difference of custom log= " << std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin).count() << "[µs]" << std::endl;
  17.  
  18.  
  19. begin = std::chrono::steady_clock::now();
  20. std::log(10);
  21. end = std::chrono::steady_clock::now();
  22. std::cout << "Time difference of std log= " << std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin).count() << "[µs]" << std::endl;
  23. }
Success #stdin #stdout 0.01s 5648KB
stdin
Standard input is empty
stdout
Time difference of custom log= 213[µs]
Time difference of std log= 60[µs]