Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. // ConsoleApplication1.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <chrono>
  7.  
  8. using namespace std;
  9.  
  10. template<int N>
  11. class Factorial {
  12. public:
  13. enum { value = N * Factorial<N - 1>::value };
  14. };
  15. template<>
  16. class Factorial<1> {
  17. public:
  18. enum { value = 1 };
  19. };
  20.  
  21. int main()
  22. {
  23. std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
  24. std::cout << Factorial<10>::value;
  25. std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
  26.  
  27. std::cout << "Time difference = " << std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() << "[µs]" << std::endl;
  28.  
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement