Changeset View
Changeset View
Standalone View
Standalone View
autotests/benchmarks/positioncodecbenchmark.cpp
Show All 25 Lines | |||||
26 | 26 | | |||
27 | using namespace Baloo; | 27 | using namespace Baloo; | ||
28 | 28 | | |||
29 | class PositionCodecBenchmark : public QObject | 29 | class PositionCodecBenchmark : public QObject | ||
30 | { | 30 | { | ||
31 | Q_OBJECT | 31 | Q_OBJECT | ||
32 | private Q_SLOTS: | 32 | private Q_SLOTS: | ||
33 | void initTestCase(); | 33 | void initTestCase(); | ||
34 | // data 1 - a lot of positions, small amount of PositionInfo | 34 | // data 1 - small number of documents, each with many positions | ||
35 | void benchEncodeData1(); | 35 | void benchEncodeData1(); | ||
36 | void benchDecodeData1(); | 36 | void benchDecodeData1(); | ||
37 | // data 2 - few positions, large amount of PositionInfo | 37 | // data 2 - large number of documents, few positions (10) each | ||
38 | void benchEncodeData2(); | 38 | void benchEncodeData2(); | ||
39 | void benchDecodeData2(); | 39 | void benchDecodeData2(); | ||
40 | // data 3 - small number of documents, many positions with large increment | ||||
41 | void benchEncodeData3(); | ||||
42 | void benchDecodeData3(); | ||||
40 | private: | 43 | private: | ||
41 | QVector<PositionInfo> m_benchmarkData1; | 44 | QVector<PositionInfo> m_benchmarkData1; | ||
42 | QVector<PositionInfo> m_benchmarkData2; | 45 | QVector<PositionInfo> m_benchmarkData2; | ||
46 | QVector<PositionInfo> m_benchmarkData3; | ||||
43 | }; | 47 | }; | ||
44 | 48 | | |||
45 | void PositionCodecBenchmark::initTestCase() | 49 | void PositionCodecBenchmark::initTestCase() | ||
46 | { | 50 | { | ||
51 | /* | ||||
52 | * Same dataset as in autotests/unit/codecs/positioncodectest.cpp | ||||
53 | * Correctness of encoding/decoding is checked there. | ||||
54 | */ | ||||
47 | m_benchmarkData1.clear(); | 55 | m_benchmarkData1.clear(); | ||
48 | m_benchmarkData1.reserve(100); | 56 | m_benchmarkData1.reserve(100); | ||
49 | for(int i = 0; i < 100; ++i) | 57 | for(int i = 0; i < 100; ++i) | ||
50 | { | 58 | { | ||
51 | PositionInfo info; | 59 | PositionInfo info; | ||
52 | info.docId = (i + 1) * 4711; | 60 | info.docId = (i + 1) * 4711; | ||
53 | info.positions.reserve(3000); | 61 | info.positions.reserve(3000); | ||
54 | for (int j = 0; j < 3000; j++) | 62 | for (int j = 0; j < 3000; j++) | ||
55 | info.positions.append(((j + 1) * 42) / info.docId); | 63 | info.positions.append(((j + 1) * (i + 2))); | ||
56 | m_benchmarkData1.append(info); | 64 | m_benchmarkData1.append(info); | ||
57 | } | 65 | } | ||
58 | 66 | | |||
59 | m_benchmarkData2.clear(); | 67 | m_benchmarkData2.clear(); | ||
60 | m_benchmarkData2.reserve(5000); | 68 | m_benchmarkData2.reserve(5000); | ||
61 | for (int i = 0; i < 5000; i++) { | 69 | for (int i = 0; i < 5000; i++) { | ||
62 | PositionInfo info; | 70 | PositionInfo info; | ||
63 | info.docId = i; | 71 | info.docId = i; | ||
64 | info.positions = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | 72 | info.positions = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | ||
65 | 73 | | |||
66 | m_benchmarkData2.append(info); | 74 | m_benchmarkData2.append(info); | ||
67 | } | 75 | } | ||
68 | 76 | | |||
77 | m_benchmarkData3.clear(); | ||||
78 | m_benchmarkData3.reserve(200); | ||||
79 | for (int i = 0; i < 200; i++) { | ||||
80 | PositionInfo info; | ||||
81 | info.docId = i; | ||||
82 | info.positions.reserve(30000); // > 2^14 -> 3 byte VarInt32 | ||||
83 | for (int j = 0; j < 30000; j++) | ||||
84 | info.positions.append((j + 1) * 200); // increment 200 -> 2 byte DiffVarInt32 | ||||
85 | | ||||
86 | m_benchmarkData3.append(info); | ||||
87 | } | ||||
69 | } | 88 | } | ||
70 | 89 | | |||
71 | void PositionCodecBenchmark::benchEncodeData1() | 90 | void PositionCodecBenchmark::benchEncodeData1() | ||
72 | { | 91 | { | ||
73 | PositionCodec pc; | 92 | PositionCodec pc; | ||
74 | QBENCHMARK { pc.encode(m_benchmarkData1); } | 93 | QBENCHMARK { pc.encode(m_benchmarkData1); } | ||
75 | } | 94 | } | ||
76 | 95 | | |||
Show All 12 Lines | |||||
89 | 108 | | |||
90 | void PositionCodecBenchmark::benchDecodeData2() | 109 | void PositionCodecBenchmark::benchDecodeData2() | ||
91 | { | 110 | { | ||
92 | PositionCodec pc; | 111 | PositionCodec pc; | ||
93 | const QByteArray ba = pc.encode(m_benchmarkData2); | 112 | const QByteArray ba = pc.encode(m_benchmarkData2); | ||
94 | QBENCHMARK { pc.decode(ba); } | 113 | QBENCHMARK { pc.decode(ba); } | ||
95 | } | 114 | } | ||
96 | 115 | | |||
116 | void PositionCodecBenchmark::benchEncodeData3() | ||||
117 | { | ||||
118 | PositionCodec pc; | ||||
119 | QBENCHMARK { pc.encode(m_benchmarkData3); } | ||||
120 | } | ||||
121 | | ||||
122 | void PositionCodecBenchmark::benchDecodeData3() | ||||
123 | { | ||||
124 | PositionCodec pc; | ||||
125 | const QByteArray ba = pc.encode(m_benchmarkData3); | ||||
126 | QBENCHMARK { pc.decode(ba); } | ||||
127 | } | ||||
128 | | ||||
97 | QTEST_MAIN(PositionCodecBenchmark) | 129 | QTEST_MAIN(PositionCodecBenchmark) | ||
98 | 130 | | |||
99 | #include "positioncodecbenchmark.moc" | 131 | #include "positioncodecbenchmark.moc" |