daily pastebin goal
3%
SHARE
TWEET

step1.c

a guest Dec 19th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdint.h>
  3.  
  4. union ticks
  5. {
  6.     uint64_t t64;
  7.     struct s32
  8.     {
  9.         uint32_t th,tl;
  10.     } t32;
  11. };
  12.  
  13.  
  14. void step1(int LSpy) {
  15.     union ticks start, end;
  16.  
  17.     int long unsigned i;
  18.     int a = 1;
  19.     int long unsigned liter = 10000;
  20.     uint64_t max_result = 0;
  21.  
  22.     for (i = 0; i < liter * 10; ++i) {
  23.         if ((i % LSpy) == 0) {
  24.             a = 0;
  25.         }
  26.     }
  27.  
  28.     uint64_t result = 0;
  29.     for (i = 0; i < liter; ++i) {
  30.         asm("rdtsc\n\t":"=a"(start.t32.th),"=d"(start.t32.tl));
  31.  
  32.         if ((i % LSpy) == 0) {
  33.             a = 0;
  34.             asm("rdtsc\n\t":"=a"(end.t32.th),"=d"(end.t32.tl));
  35.             result = end.t64-start.t64;
  36.         }
  37.         else a=1;
  38.     }
  39.     printf("%d %lu\n", LSpy, result);
  40.    
  41. }
  42.  
  43. int main() {
  44.     int testsAmount = 512;
  45.     for (int i = 1; i <= testsAmount; ++i) {
  46.         step1(i);
  47.     }
  48.     return 0;
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top