Overview
| Artifact ID: | 9d83f4be3bd428dc506a432fef4448cb630c2428 |
|---|---|
| Ticket: | 951168ffffffffffffffffffffffffffffffffff
strcmp in CompareStringKeys |
| User & Date: | nobody on 2004-05-13 19:43:15 |
Changes
- icomment:
Logged In: NO Hi I just wrote this little performance test. On Solaris and Linux machine strcmp seems to be twice faster. #define __NO_STRING_INLINES /* get optimized assembly version of strcmp with glibc */ #include <string.h> #include <time.h> int test1(const char* a, const char* b) { return strcmp(a, b); } int test2(const char* p1, const char* p2) { for (;; p1++, p2++) { if (*p1 != *p2) { break; } if (*p1 == '\0') { return 1; } } return 0; } int main() { char a[128]; char b[128]; int i; clock_t start, end; strcpy(a, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); strcpy(b, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"); start = clock(); for (i=0; i< 1000000;i++) test1(a, b); end = clock(); printf("strcmp time = %d\n", end-start); start = clock(); for (i=0; i< 1000000;i++) test2(a, b); end = clock(); printf("own time = %d\n", end-start); return 0; } - login: "nobody"
- mimetype: "text/plain"
- username: "nobody"