ttest.cpp

来自「c++的一些源代码」· C++ 代码 · 共 53 行

CPP
53
字号
#include    <stdio.h>
#include    <time.h>

void    TimeTestIndex();
void    TimeTestPointer();

int main()
{
time_t tStart, tEnd;
long y;

    time (&tStart);
    for (y = 0; y < 10000000; ++y)
        TimeTestIndex();
    time (&tEnd);
    printf ("Time elapsed = %ld\n", tEnd - tStart);

    time (&tStart);
    for (y = 0; y < 10000000; ++y)
        TimeTestPointer();
    time (&tEnd);
    printf ("Time elapsed = %ld\n", tEnd - tStart);
    return (0);
}

void TimeTestIndex()
{
char str1[] = "The quick red fox jumps over the "
              "lazy dog's back. RY Testing";
char str2[124];
int    i = 0;
int    j = sizeof (str1);

    do
        {
        str2[i] = str1[i];
        } while (i++ < j);
}

void TimeTestPointer()
{
char str1[] = "The quick red fox jumps over the "
              "lazy dog's back. RY Testing";
char str2[124];
char *pstr1 = str1;
char *pstr2 = str2;

    do
        {
        *pstr2++ = *pstr1++;
        } while (*pstr1);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?