Home
Phabricator
Search
Log In
Files
F5734576
qsort_performance_test.cpp
jtamate (Jaime Torres Amate)
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Author
jtamate
Created
Mar 1 2018, 7:57 AM
Size
1 KB
Mime Type
text/x-c
Engine
blob
Format
Raw Data
Handle
3502438
Attached To
D10857: Change qSort to std::sort
qsort_performance_test.cpp
View Options
// Written by Mark Gaiser
// Modified by David Faure
// Modified by Jaime Torres
#include
<QCoreApplication>
#include
<QtAlgorithms>
#include
<QString>
#include
<QUrl>
#include
<QList>
#include
<QElapsedTimer>
#include
<QDebug>
#include
<vector>
#include
<random>
#include
<algorithm>
static
bool
lessThan
(
const
QUrl
&
left
,
const
QUrl
&
right
)
{
return
left
.
toString
().
compare
(
right
.
toString
())
<
0
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
QCoreApplication
a
(
argc
,
argv
);
// Fill input vector with data.
QList
<
QUrl
>
inputData
;
inputData
.
append
(
QUrl
(
QString
(
"file:///home/user/borrar/grandes"
)));
inputData
.
append
(
QUrl
(
QString
(
"file:///home/user/borrar/a"
)));
inputData
.
append
(
QUrl
(
QString
(
"file:///home/user/borrar/b"
)));
inputData
.
append
(
QUrl
(
QString
(
"file:///home/user/borrar/c"
)));
for
(
int
i
=
0
;
i
<
50000
;
i
++
)
{
inputData
.
append
(
QUrl
(
QString
(
"file:///home/user/borrar/fichero%1.txt"
).
arg
(
i
)
));
}
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
{
// Copies the data in a new vector
QList
<
QUrl
>
data
(
inputData
);
QElapsedTimer
timer
;
timer
.
start
();
qSort
(
data
.
begin
(),
data
.
end
(),
lessThan
);
qDebug
()
<<
QString
(
"qSort took: %1 ms"
).
arg
(
timer
.
elapsed
());
}
{
// Copies the data in a new vector
QList
<
QUrl
>
data
(
inputData
);
QElapsedTimer
timer
;
timer
.
start
();
std
::
sort
(
data
.
begin
(),
data
.
end
(),
lessThan
);
qDebug
()
<<
QString
(
"std::sort took: %1 ms"
).
arg
(
timer
.
elapsed
());
}
}
return
0
;
}
Log In to Comment