All pastes #910992 Raw Edit

Miscellany

public cpp v1 · immutable
·published 2008-02-20 11:59 UTC
rendered paste body
#include <QTime>#include <QDebug>#include <QByteArray>#include <string.h>int main(){    static const char message[] =        "This is the message that is copied around "        "and around. The whole point is that I will "        "create a QByteArray object or a const char* "        "to hold this, then copy it, then delete it.\n"        "No more, no less";    static const int len = sizeof message;    QTime timer;    timer.start();    for (int i = 0; i < 1000; ++i) {        char *ptr = new char[len];        memcpy(ptr, message, len);        delete[] ptr;    }    qDebug() << timer.elapsed();    timer.start();    for (int i = 0; i < 1000; ++i) {        QByteArray array(message, len - 1);    }    qDebug() << timer.elapsed();}