Created
February 1, 2016 20:53
-
-
Save clausecker/6bfe94c00ccc6f4ddcb1 to your computer and use it in GitHub Desktop.
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> | |
| #include <time.h> | |
| #include <string.h> | |
| #include <stdlib.h> | |
| #define TESTS 10000000 | |
| #ifndef MISALIGNED | |
| # define MISALIGNED 0 | |
| #endif | |
| char testarray[512 + MISALIGNED]; | |
| extern int is_eof_block(const char[static 512]); | |
| int main() | |
| { | |
| size_t i, j; | |
| clock_t begin, end; | |
| fprintf(stderr, "testing %d times\n", TESTS); | |
| fprintf(stderr, "no byte set to 1... "); | |
| begin = clock(); | |
| for (i = 0; i < TESTS; i++) | |
| if (!is_eof_block(testarray + MISALIGNED)) { | |
| fprintf(stderr, "\nWrong test result in iteration %zu!\n", i); | |
| return EXIT_FAILURE; | |
| } | |
| end = clock(); | |
| fprintf(stderr, "%fs\n", (end - begin) / (double)CLOCKS_PER_SEC); | |
| fprintf(stderr, "with non-null byte... "); | |
| begin = clock(); | |
| for (i = j = 0; i < TESTS; i++) { | |
| testarray[MISALIGNED + j] = '\0'; | |
| j = (j + 47) & 511; | |
| testarray[MISALIGNED + j] = '1'; | |
| if (is_eof_block(testarray + MISALIGNED)) { | |
| fprintf(stderr, "\nWrong test result in iteration %zu!\n", i); | |
| return EXIT_FAILURE; | |
| } | |
| } | |
| end = clock(); | |
| fprintf(stderr, "%fs\n", (end - begin) / (double)CLOCKS_PER_SEC); | |
| testarray[MISALIGNED + j] = '\0'; | |
| testarray[MISALIGNED] = '1'; | |
| fprintf(stderr, "first byte set to 1... "); | |
| begin = clock(); | |
| for (i = 0; i < TESTS; i++) | |
| if (is_eof_block(testarray + MISALIGNED)) { | |
| fprintf(stderr, "\nWrong test result in iteration %zu!\n", i); | |
| return EXIT_FAILURE; | |
| } | |
| end = clock(); | |
| fprintf(stderr, "%fs\n", (end - begin) / (double)CLOCKS_PER_SEC); | |
| return EXIT_SUCCESS; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment