-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestQtNotifyPerformance.cc
85 lines (68 loc) · 1.95 KB
/
testQtNotifyPerformance.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <QScopedPointer>
#include <QCoreApplication>
#include <QTimer>
#include <iostream>
#include <chrono>
using namespace std;
using namespace std::chrono;
class TestEmitter: public QObject
{
Q_OBJECT
public:
TestEmitter(QObject *parent = 0): QObject(parent) {}
void paste(int s0, int s1, const QByteArray &chunk = QByteArray()) {
// doSmth...
emit textChanged(s0, s1, chunk);
}
signals:
void textChanged(int s0, int s1, const QByteArray &chunk);
};
class TestReceiver: public QObject
{
Q_OBJECT
public:
TestReceiver(QObject *parent = 0): QObject(parent), dummy_(0) {}
void onTextChanged(int s0, int s1, const QByteArray &chunk) {
dummy_ += (s0 * s1);
}
private:
int dummy_;
};
class BulkEmissionTest: public QObject
{
public:
BulkEmissionTest(QObject *parent = 0):
QObject(parent),
e_(new TestEmitter(this)),
r_(new TestReceiver(this))
{
connect(e_, &TestEmitter::textChanged, r_, &TestReceiver::onTextChanged);
QTimer *t = new QTimer(this);
connect(t, &QTimer::timeout, this, &BulkEmissionTest::run);
t->setSingleShot(true);
t->start(0);
}
void run() {
cout << "run()..." << endl;
QByteArray chunk = "Abc";
high_resolution_clock::time_point t0 = high_resolution_clock::now();
const int n = 10000000;
for (int i = 0; i < n; ++i)
e_->paste(i, i + 1, chunk);
high_resolution_clock::time_point t1 = high_resolution_clock::now();
double dt = duration_cast<duration<double>>(t1 - t0).count();
cout << "took " << dt << " s" << endl;
cout << "=> " << n / dt << " Hz" << endl;
QCoreApplication::instance()->quit();
}
private:
TestEmitter *e_;
TestReceiver *r_;
};
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
new BulkEmissionTest(&app);
return app.exec();
}
#include "moc_testQtNotifyPerformance.cc"