author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 3 | 41300fa6a67c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include <QtTest/QtTest> |
|
43 |
||
44 |
#ifdef Q_OS_WIN |
|
45 |
# include <windows.h> |
|
46 |
#else |
|
47 |
# include <sys/stat.h> |
|
48 |
# include <sys/types.h> |
|
49 |
# include <dirent.h> |
|
50 |
# include <unistd.h> |
|
51 |
#endif |
|
52 |
||
53 |
class Test : public QObject{ |
|
54 |
Q_OBJECT |
|
55 |
public slots: |
|
56 |
void initTestCase() { |
|
57 |
QDir testdir = QDir::tempPath(); |
|
58 |
||
59 |
const QString subfolder_name = QLatin1String("test_speed"); |
|
60 |
QVERIFY(testdir.mkdir(subfolder_name)); |
|
61 |
QVERIFY(testdir.cd(subfolder_name)); |
|
62 |
||
63 |
for (uint i=0; i<10000; ++i) { |
|
64 |
QFile file(testdir.absolutePath() + "/testfile_" + QString::number(i)); |
|
65 |
file.open(QIODevice::WriteOnly); |
|
66 |
} |
|
67 |
} |
|
68 |
void cleanupTestCase() { |
|
69 |
{ |
|
70 |
QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
71 |
testdir.setSorting(QDir::Unsorted); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
72 |
testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden); |
0 | 73 |
foreach (const QString &filename, testdir.entryList()) { |
74 |
testdir.remove(filename); |
|
75 |
} |
|
76 |
} |
|
77 |
const QDir temp = QDir(QDir::tempPath()); |
|
78 |
temp.rmdir(QLatin1String("test_speed")); |
|
79 |
} |
|
80 |
private slots: |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
81 |
void baseline() {} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
82 |
|
0 | 83 |
void sizeSpeed() { |
84 |
QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); |
|
85 |
QBENCHMARK { |
|
86 |
QFileInfoList fileInfoList = testdir.entryInfoList(QDir::Files, QDir::Unsorted); |
|
87 |
foreach (const QFileInfo &fileInfo, fileInfoList) { |
|
88 |
fileInfo.isDir(); |
|
89 |
fileInfo.size(); |
|
90 |
} |
|
91 |
} |
|
92 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
93 |
void sizeSpeedIterator() { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
94 |
QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
95 |
QBENCHMARK { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
96 |
QDirIterator dit(testdir.path(), QDir::Files); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
97 |
while (dit.hasNext()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
98 |
dit.fileInfo().isDir(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
99 |
dit.fileInfo().size(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
100 |
dit.next(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
101 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
102 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
103 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
104 |
|
0 | 105 |
void sizeSpeedWithoutFilter() { |
106 |
QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); |
|
107 |
QBENCHMARK { |
|
108 |
QFileInfoList fileInfoList = testdir.entryInfoList(QDir::NoFilter, QDir::Unsorted); |
|
109 |
foreach (const QFileInfo &fileInfo, fileInfoList) { |
|
110 |
fileInfo.size(); |
|
111 |
} |
|
112 |
} |
|
113 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
114 |
void sizeSpeedWithoutFilterIterator() { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
115 |
QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
116 |
QBENCHMARK { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
117 |
QDirIterator dit(testdir.path()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
118 |
while (dit.hasNext()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
119 |
dit.fileInfo().isDir(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
120 |
dit.fileInfo().size(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
121 |
dit.next(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
122 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
123 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
124 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
125 |
|
0 | 126 |
void sizeSpeedWithoutFileInfoList() { |
127 |
QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); |
|
128 |
testdir.setSorting(QDir::Unsorted); |
|
129 |
QBENCHMARK { |
|
130 |
QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted); |
|
131 |
foreach (const QString &filename, fileList) { |
|
132 |
QFileInfo fileInfo(filename); |
|
133 |
fileInfo.size(); |
|
134 |
} |
|
135 |
} |
|
136 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
137 |
|
0 | 138 |
void iDontWantAnyStat() { |
139 |
QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); |
|
140 |
testdir.setSorting(QDir::Unsorted); |
|
141 |
testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden); |
|
142 |
QBENCHMARK { |
|
143 |
QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted); |
|
144 |
foreach (const QString &filename, fileList) { |
|
145 |
||
146 |
} |
|
147 |
} |
|
148 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
149 |
void iDontWantAnyStatIterator() { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
QBENCHMARK { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
151 |
QDirIterator dit(QDir::tempPath() + QLatin1String("/test_speed")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
152 |
while (dit.hasNext()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
153 |
dit.next(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
154 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
155 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
156 |
} |
0 | 157 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
158 |
void sizeSpeedWithoutFilterLowLevel() { |
0 | 159 |
#ifdef Q_OS_WIN |
160 |
const wchar_t *dirpath = (wchar_t*)testdir.absolutePath().utf16(); |
|
161 |
wchar_t appendedPath[MAX_PATH]; |
|
162 |
wcscpy(appendedPath, dirpath); |
|
163 |
wcscat(appendedPath, L"\\*"); |
|
164 |
||
165 |
WIN32_FIND_DATA fd; |
|
166 |
HANDLE hSearch = FindFirstFileW(appendedPath, &fd); |
|
167 |
QVERIFY(hSearch == INVALID_HANDLE_VALUE); |
|
168 |
||
169 |
QBENCHMARK { |
|
170 |
do { |
|
171 |
||
172 |
} while (FindNextFile(hSearch, &fd)); |
|
173 |
} |
|
174 |
FindClose(hSearch); |
|
175 |
#else |
|
176 |
QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); |
|
177 |
DIR *dir = opendir(qPrintable(testdir.absolutePath())); |
|
178 |
QVERIFY(dir); |
|
179 |
||
180 |
QVERIFY(!chdir(qPrintable(testdir.absolutePath()))); |
|
181 |
QBENCHMARK { |
|
182 |
struct dirent *item = readdir(dir); |
|
183 |
while (item) { |
|
184 |
char *fileName = item->d_name; |
|
185 |
||
186 |
struct stat fileStat; |
|
187 |
QVERIFY(!stat(fileName, &fileStat)); |
|
188 |
||
189 |
item = readdir(dir); |
|
190 |
} |
|
191 |
} |
|
192 |
closedir(dir); |
|
193 |
#endif |
|
194 |
} |
|
195 |
}; |
|
196 |
||
197 |
QTEST_MAIN(Test) |
|
198 |
#include "tst_qdir.moc" |