Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. #include <stddef.h>
  2. #include <time.h>
  3. #include <stdio.h>
  4.  
  5. int main()
  6. {
  7.  
  8.     int x = 2;
  9.  
  10.     clock_t end = clock();
  11.     clock_t start = clock();
  12.  
  13.     for(uint32_t i = 0; i < 100000000; ++i)
  14.     {
  15.         if(x < 4){
  16.             int y = x * x;
  17.         }
  18.     }
  19.     end = clock();
  20.     printf("Int if Done in %f\n", (float) (end - start) / CLOCKS_PER_SEC);
  21.  
  22.     start = clock();
  23.     for(uint32_t i = 0; i < 100000000; ++i)
  24.     {
  25.         int32_t blah = (uint32_t) (x - 4) >> 31;
  26.         if(blah)
  27.             int y = x * x;
  28.     }
  29.     end = clock();
  30.     printf("Int mask Done in %f\n\n", (float) (end - start) / CLOCKS_PER_SEC);
  31.  
  32.  
  33.     start = clock();
  34.     float z = 2.0f;
  35.     for(uint32_t i = 0; i < 100000000; ++i)
  36.     {
  37.         if(z < 4.0f){
  38.             int y = x * x;
  39.         }
  40.     }
  41.     end = clock();
  42.     printf("float if Done in %f\n", (float) (end - start) / CLOCKS_PER_SEC);
  43.  
  44.     start = clock();
  45.     for(uint32_t i = 0; i < 100000000; ++i)
  46.     {
  47.         int32_t blah = (uint32_t) (z - 4.0f) >> 31;
  48.         if(blah)
  49.             int y = x * x;
  50.     }
  51.     end = clock();
  52.     printf("float mask Done in %f\n", (float) (end - start) / CLOCKS_PER_SEC);
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement