Advertisement
Semper_Idem

linear time

Apr 2nd, 2020
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. svetoslave@vm-ubuntu-svetoslave:~/scratch$ cat linear.c
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. int main(int argc, char *argv[]) {
  6.     long long x = strtoll(argv[1], NULL, 0);
  7.     printf("Iterating %lld times\n", x);
  8.     for (long long i = 0; i < x; i++) {
  9.         asm volatile("nop");
  10.     }
  11.     printf("Done\n");
  12.     return 0;
  13. }
  14.  
  15. svetoslave@vm-ubuntu-svetoslave:~/scratch$ time ./linear 10000
  16. Iterating 10000 times
  17. Done
  18.  
  19. real    0m0,001s
  20. user    0m0,001s
  21. sys 0m0,000s
  22. svetoslave@vm-ubuntu-svetoslave:~/scratch$ time ./linear 100000
  23. Iterating 100000 times
  24. Done
  25.  
  26. real    0m0,001s
  27. user    0m0,001s
  28. sys 0m0,000s
  29. svetoslave@vm-ubuntu-svetoslave:~/scratch$ time ./linear 1000000
  30. Iterating 1000000 times
  31. Done
  32.  
  33. real    0m0,003s
  34. user    0m0,002s
  35. sys 0m0,000s
  36. svetoslave@vm-ubuntu-svetoslave:~/scratch$ time ./linear 10000000
  37. Iterating 10000000 times
  38. Done
  39.  
  40. real    0m0,020s
  41. user    0m0,020s
  42. sys 0m0,000s
  43. svetoslave@vm-ubuntu-svetoslave:~/scratch$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement