server: base server code.
This commit is contained in:
83
Test/infoTest.cpp
Normal file
83
Test/infoTest.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#include "infoTest.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QElapsedTimer>
|
||||
|
||||
int infoTest1()
|
||||
{
|
||||
InfoClient ic;
|
||||
ic.id = "1234567890";
|
||||
ic.name = "Test";
|
||||
|
||||
InfoClientVec vec;
|
||||
vec.vec.append(ic);
|
||||
|
||||
QByteArray qa;
|
||||
QBuffer buf(&qa);
|
||||
buf.open(QIODevice::ReadWrite);
|
||||
|
||||
QDataStream qs(&buf);
|
||||
vec.serialize(qs);
|
||||
buf.close();
|
||||
|
||||
qDebug() << "Serialized data size:" << qa.size();
|
||||
qDebug() << "Serialized data:" << qa.toHex();
|
||||
|
||||
QBuffer buf2(&qa);
|
||||
buf2.open(QIODevice::ReadWrite);
|
||||
QDataStream qs2(&buf2);
|
||||
InfoClientVec vec2;
|
||||
vec2.deserialize(qs2);
|
||||
buf2.close();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int infoTest2()
|
||||
{
|
||||
InfoClient ic;
|
||||
ic.id = "1234567890";
|
||||
ic.name = "Test";
|
||||
|
||||
InfoClientVec vec;
|
||||
vec.vec.append(ic);
|
||||
|
||||
QByteArray qa;
|
||||
QDataStream qs(&qa, QIODevice::ReadWrite);
|
||||
vec.serialize(qs);
|
||||
|
||||
qDebug() << "Serialized data size:" << qa.size();
|
||||
qDebug() << "Serialized data:" << qa.toHex();
|
||||
|
||||
qs.device()->seek(0);
|
||||
InfoClientVec vec2;
|
||||
vec2.deserialize(qs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void performanceTest()
|
||||
{
|
||||
QByteArray data;
|
||||
QElapsedTimer timer;
|
||||
|
||||
timer.start();
|
||||
QDataStream stream(&data, QIODevice::ReadWrite);
|
||||
for (int i = 0; i < 10000; ++i) {
|
||||
stream << i;
|
||||
stream.device()->seek(0);
|
||||
int val;
|
||||
stream >> val;
|
||||
}
|
||||
qDebug() << "Reuse stream:" << timer.elapsed() << "ms";
|
||||
|
||||
timer.start();
|
||||
for (int i = 0; i < 10000; ++i) {
|
||||
QDataStream out(&data, QIODevice::WriteOnly);
|
||||
out << i;
|
||||
QDataStream in(&data, QIODevice::ReadOnly);
|
||||
int val;
|
||||
in >> val;
|
||||
}
|
||||
qDebug() << "New streams:" << timer.elapsed() << "ms";
|
||||
}
|
||||
Reference in New Issue
Block a user