设为首页 加入收藏

TOP

写高并发程序时慎用strncpy和sprintf(三)
2019-01-05 20:09:04 】 浏览:508
Tags:并发 程序 慎用 strncpy sprintf
f
("test strcpy")); } PerformanceTestLog(TEST_LOG_INF, "test strcmp"); for (i = 0; i < nTimes; ++i) { if (0 == strcmp(tmp, "test strcpy")) { i = i; } } PerformanceTestLog(TEST_LOG_INF, "test memcmp"); for (i = 0; i < nTimes; ++i) { if (0 == memcmp(tmp, "test strcpy", sizeof("test strcpy"))) { i = i; } } PerformanceTestLog(TEST_LOG_INF, "test strcpy1"); for (i = 0; i < nTimes; ++i) { strcpy(tmp, "test strcpy test strcpy test strcpy test strcpy test strcpytest strcpy"); } PerformanceTestLog(TEST_LOG_INF, "test memcpy1"); for (i = 0; i < nTimes; ++i) { memcpy(tmp, "test strcpy test strcpy test strcpy test strcpy test strcpytest strcpy", sizeof("test strcpy test strcpy test strcpy test strcpy test strcpytest strcpy")); } PerformanceTestLog(TEST_LOG_INF, "test strcmp1"); for (i = 0; i < nTimes; ++i) { if (0 == strcmp(tmp, "test strcpy test strcpy test strcpy test strcpy test strcpytest strcpy")) { i = i; } } PerformanceTestLog(TEST_LOG_INF, "test memcmp1"); for (i = 0; i < nTimes; ++i) { if (0 == memcmp(tmp, "test strcpy test strcpy test strcpy test strcpy test strcpytest strcpy", sizeof("test strcpy test strcpy test strcpy test strcpy test strcpytest strcpy"))) { i = i; } } stopTimer(TEST_LOG_INF, 0); nTimes /= 5; //8千万 WriteLog(LOG_KEY, "BaseTest %lu", nTimes); PerformanceTestLog(TEST_LOG_INF, "test sprintf"); for (i = 0; i < nTimes; ++i) { sprintf(tmp, "thiis %s testing %d", "sprintf", i); } PerformanceTestLog(TEST_LOG_INF, "test sscanf"); for (i = 0; i < nTimes; ++i) { sscanf(tmp, "%s %s %s %d", t1, t2, t3, &nTmp); } { FILE *fp; int nStr; PerformanceTestLog(TEST_LOG_INF, "fopen"); fp = fopen("performancetest.txt", "w"); strWriten = "this is testing write\n"; nStr = strlen(strWriten); PerformanceTestLog(TEST_LOG_INF, "test write file"); for (i = 0; i < nTimes; ++i) { fwrite(strWriten, 1, nStr, fp); } PerformanceTestLog(TEST_LOG_INF, "fflush"); fflush(fp); PerformanceTestLog(TEST_LOG_INF, "test fprintf file"); for (i = 0; i < nTimes; ++i) { //太过简单的fprintf好像会被自动优化成fwrite,即使没开优化选项 //例如 fprintf(fp, "%s", "strWriten"); fprintf(fp, "%s %d\n", "strWriten", i); } PerformanceTestLog(TEST_LOG_INF, "fclose"); fclose(fp); } { FILE *fp; int nStr; PerformanceTestLog(TEST_LOG_INF, "fopen 1"); fp = fopen("performancetest.txt", "r"); nStr = strlen(strWriten); PerformanceTestLog(TEST_LOG_INF, "test read file"); for (i = 0; i < nTimes; ++i) { fread(tmp, 1, nStr, fp); tmp[nStr] = '\0'; } PerformanceTestLog(TEST_LOG_INF, "test fscanf file"); tmp[0] = t1[0] = '\0'; for (i = 0; i < nTimes; ++i) { fscanf(fp, "%s %s", tmp, t1); } PerformanceTestLog(TEST_LOG_INF, "fclose"); fclose(fp); } fclose(fopen("performancetest.txt", "w")); nTime
首页 上一页 1 2 3 4 下一页 尾页 3/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇cf121C. Lucky Permutation(康托.. 下一篇洛谷P2973 [USACO10HOL]赶小猪(高..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目