Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stddef.h>
- #include <time.h>
- #include <stdio.h>
- int main()
- {
- int x = 2;
- clock_t end = clock();
- clock_t start = clock();
- for(uint32_t i = 0; i < 100000000; ++i)
- {
- if(x < 4){
- int y = x * x;
- }
- }
- end = clock();
- printf("Int if Done in %f\n", (float) (end - start) / CLOCKS_PER_SEC);
- start = clock();
- for(uint32_t i = 0; i < 100000000; ++i)
- {
- int32_t blah = (uint32_t) (x - 4) >> 31;
- if(blah)
- int y = x * x;
- }
- end = clock();
- printf("Int mask Done in %f\n\n", (float) (end - start) / CLOCKS_PER_SEC);
- start = clock();
- float z = 2.0f;
- for(uint32_t i = 0; i < 100000000; ++i)
- {
- if(z < 4.0f){
- int y = x * x;
- }
- }
- end = clock();
- printf("float if Done in %f\n", (float) (end - start) / CLOCKS_PER_SEC);
- start = clock();
- for(uint32_t i = 0; i < 100000000; ++i)
- {
- int32_t blah = (uint32_t) (z - 4.0f) >> 31;
- if(blah)
- int y = x * x;
- }
- end = clock();
- printf("float mask Done in %f\n", (float) (end - start) / CLOCKS_PER_SEC);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement