Last active
August 29, 2015 14:09
-
-
Save H2CO3/553c47418e953c3e7e9f to your computer and use it in GitHub Desktop.
Argument passing benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| unsigned long fib1(unsigned long n) | |
| { | |
| return n < 2 ? 1 : fib1(n - 1) + fib1(n - 2); | |
| } | |
| unsigned long fib2(unsigned long n, unsigned long m) | |
| { | |
| return n < 2 ? 1 : fib2(n - 1, m) + fib2(n - 2, m); | |
| } | |
| int main() | |
| { | |
| #if TWOARGS | |
| printf("%lu\n", fib2(40, 0)); | |
| #else | |
| printf("%lu\n", fib1(40)); | |
| #endif | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| volatile int a; | |
| void foo(volatile int *arg) | |
| { | |
| *arg = 1337; | |
| } | |
| int main() | |
| { | |
| void (*volatile fptr)(volatile int *); | |
| fptr = &foo; | |
| for (unsigned long i = 0; i < 1000000000ul; i++) { | |
| fptr(&a); | |
| } | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| volatile int a; | |
| volatile int b; | |
| void foo(volatile int *arg1, volatile int *arg2) | |
| { | |
| *arg1 = 1337; | |
| } | |
| int main() | |
| { | |
| void (*volatile fptr)(volatile int *, volatile int *); | |
| fptr = &foo; | |
| for (unsigned long i = 0; i < 1000000000ul; i++) { | |
| fptr(&a, &b); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment