Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Emit.cpp « tests « src - github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8250bf6a9ff508b919d4573a1308bb03e4a19f98 (plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2009-2021 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

#include "Timer.h"
#include <QtCore>
#include <boost/bind.hpp>
#include <boost/signals.hpp>

class Slotter : public QObject {
	Q_OBJECT;

public:
	Slotter(QObject *p = nullptr) : QObject(p){};
public Q_SLOTS:
	virtual void slottest(int &res) { res += 1; };
};

class Emitter : public QObject {
	Q_OBJECT;

public:
	Slotter *s;
	Emitter(Slotter *s) : QObject(s) { this->s = s; };

	boost::signal< void(int &) > bsig;
Q_SIGNALS:
	void sig(int &);
public Q_SLOTS:
	void emittest(int &val) { Q_EMIT sig(val); };
	void directtest(int &val) { s->slottest(val); };
	void boosttest(int &val) { bsig(val); }
};

int main(int argc, char **argv) {
	QCoreApplication a(argc, argv);
	Timer t;

	Slotter *s  = new Slotter();
	Slotter *s2 = new Slotter();
	Emitter *e  = new Emitter(s);

	int v;

	v = 0;
	t.restart();
	for (int i = 0; i < 1000000; ++i)
		s->slottest(v);
	printf("Raw   : %8lld %d\n", t.elapsed(), v);

	v = 0;
	t.restart();
	for (int i = 0; i < 1000000; ++i)
		e->directtest(v);
	printf("Direct: %8lld %d\n", t.elapsed(), v);

	v = 0;
	t.restart();
	for (int i = 0; i < 1000000; ++i)
		e->emittest(v);
	printf("NoSig : %8lld %d\n", t.elapsed(), v);

	QObject::connect(e, SIGNAL(sig(int &)), s, SLOT(slottest(int &)));
	v = 0;
	t.restart();
	for (int i = 0; i < 1000000; ++i)
		e->emittest(v);
	printf("Signal: %8lld %d\n", t.elapsed(), v);

	QObject::connect(e, SIGNAL(sig(int &)), s2, SLOT(slottest(int &)));
	v = 0;
	t.restart();
	for (int i = 0; i < 1000000; ++i)
		e->emittest(v);
	printf("2Slots: %8lld %d\n", t.elapsed(), v);

	v = 0;
	t.restart();
	for (int i = 0; i < 1000000; ++i)
		e->boosttest(v);
	printf("BNoSig: %8lld %d\n", t.elapsed(), v);

	e->bsig.connect(boost::bind(&Slotter::slottest, s, _1));
	v = 0;
	t.restart();
	for (int i = 0; i < 1000000; ++i)
		e->boosttest(v);
	printf("Boost:  %8lld %d\n", t.elapsed(), v);

	e->bsig.connect(boost::bind(&Slotter::slottest, s2, _1));
	v = 0;
	t.restart();
	for (int i = 0; i < 1000000; ++i)
		e->boosttest(v);
	printf("2Boost: %8lld %d\n", t.elapsed(), v);
}

#include "Emit.moc"