其他分享
首页 > 其他分享> > qDebug | std::cout | printf性能表现

qDebug | std::cout | printf性能表现

作者:互联网

来自:Qt君

性能表现结论

测试程序

#include <QElapsedTimer>
#include <iostream>

/* 注:单独打开某个宏测试 */
//#define TEST1
//#define TEST2
//#define TEST3

int main(int argc, char *argv[])
{
#ifdef TEST1
    {
        QElapsedTimer t;
        qint64 it = 0;
        t.start();
        while (t.elapsed() < 1000) {
            qDebug() << "Test1";
            it++;
        }

        qDebug() << "Test1: " << it;
    }
#endif

#ifdef TEST2
    {
        QElapsedTimer t;
        qint64 it = 0;
        t.start();
        while (t.elapsed() < 1000) {
            std::cout << "Test2" << std::endl;
            it++;
        }

        std::cout << "Test2: " << it;
    }
#endif

#ifdef TEST3
    {
        QElapsedTimer t;
        qint64 it = 0;
        t.start();
        while (t.elapsed() < 1000) {
            printf("Test3\n");
            it++;
        }

        printf("Test3: %lld\n", it);
    }
#endif
	return 0
}```

标签:std,cout,性能,printf,qDebug,define
来源: https://www.cnblogs.com/Chao2020x/p/15205382.html