Last active
February 3, 2018 21:46
-
-
Save lega911/fda54b99da6665a41f66aab43557f7a0 to your computer and use it in GitHub Desktop.
This file contains 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
-O3 | |
* C: 100% (~1.14sec) | |
* C++: 99.73% | |
* C++ exception: 84.6% | |
-O2 | |
* C: 100% (~2.12sec) | |
* C++: 100.51% | |
* C++ exception: 74.02% | |
% of time, lower is better. |
This file contains 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 <time.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdint.h> | |
int64_t foo(int n, int64_t *counter) { | |
(*counter)++; | |
if(n < 2 && *counter > 500000000) return -1; | |
if(n) { | |
for(int i=0;i<n;i++) { | |
if(foo(n-1, counter) == -1) return -1; | |
} | |
} | |
return 0; | |
} | |
int main() { | |
clock_t start = clock(); | |
double duration; | |
int64_t result = 0; | |
foo(14, &result); | |
printf("result %ld\n", result); | |
duration = ( clock() - start ) / (double) CLOCKS_PER_SEC; | |
printf("Duration: %f\n", duration); | |
} | |
This file contains 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 <time.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdint.h> | |
void foo(int n, int64_t *counter) { | |
(*counter)++; | |
if(n < 2 && *counter > 500000000) throw *counter; | |
if(n) { | |
for(int i=0;i<n;i++) { | |
foo(n-1, counter); | |
} | |
} | |
} | |
int main() { | |
clock_t start = clock(); | |
double duration; | |
int64_t result = 0; | |
try { | |
foo(14, &result); | |
} catch (int64_t e) { | |
printf("exception %ld\n", e); | |
} | |
printf("result %ld\n", result); | |
duration = ( clock() - start ) / (double) CLOCKS_PER_SEC; | |
printf("Duration: %f\n", duration); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment