Created
October 9, 2011 07:19
-
-
Save indygreg/1273399 to your computer and use it in GitHub Desktop.
strtoll benchmark
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 <errno.h> | |
#include <stdio.h> | |
int main(int argc, const char **argv) { | |
if (argc != 3) { | |
printf("Usage: %s <integer> <iterations>\n", argv[0]); | |
return -1; | |
} | |
const char *input = argv[1]; | |
const char *iteration_s = argv[2]; | |
long long result = 0; | |
size_t i; | |
int iterations = strtol(argv[2], (char **)NULL, 10); | |
if (ERANGE == errno) { | |
printf("Overflow when parsing iterations\n"); | |
return -1; | |
} | |
if (iterations < 0) { | |
printf("Iterations must be positive\n"); | |
return -1; | |
} | |
for (i = iterations; i; i--) { | |
result = strtoll(input, (char **)NULL, 10); | |
} | |
printf("Finished conversion\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment