C++ (Qt)#include <iostream>#include <algorithm>#include <QtGUI> struct CData { CData( void ) { vec.resize(10); std::fill(vec.begin(), vec.end(), "test"); } std::vector <std::string> vec;}; int main(){ const int Num = 1000 * 1000; QList <CData> list; for (int i = 0; i < Num; ++i) list.push_back(CData()); qsrand(0); QTime t2 = QTime::currentTime(); int limit = list.size(); for (int i = 0; i < limit; ++i) list.swap(i, qrand() % limit); std::cout << "igors: " << t2.elapsed() << " ms." << std::endl; srand(0); QTime t1 = QTime::currentTime(); std::random_shuffle(list.begin(), list.end()); std::cout << "random_shuffle: " << t1.elapsed() << " ms." << std::endl; return 0;}
Bashigors: 226 ms.random_shuffle: 736 ms.
C++ (Qt) QStringList lst; do { itemStr = fileStream.readLine(); trimmedStr = itemStr.trimmed(); lst = +trimmedStr; } while( !fileStream.atEnd() );
C++ (Qt) QStringList lst; while(!fileStream.atEnd()) { lst.append(fileStream.readLine()); }
C++ (Qt) QFile file("in.txt"); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return; QTextStream in(&file); QStringList list = in.readAll().split(QRegExp("[\\s\n]"), QString::SkipEmptyParts);
C++ (Qt) if ( file.open( QFile::ReadOnly | QIODevice::Text ) ) { QTextStream fileStr( & file ); QStringList list = fileStr.readAll().split(QRegExp("[\\s\n]"), QString::SkipEmptyParts); for (int i = 0; i < list.size(); ++i) list.swap(qrand() % list.size(), qrand() % list.size()); foreach (QString itm, list) { if(slideShowPopupAction->isChecked())winPopup->slideTranslationFor( itm ); QEventLoop loop2; QTimer::singleShot(cfg.preferences.slideShowTimer, &loop2, SLOT(quit())); loop2.exec(); } file.close(); }
C++ (Qt) if ( file.open( QFile::ReadOnly | QIODevice::Text ) ) { QTextStream fileStr( & file ); QStringList list; while(!fileStr.atEnd()) { list.append(fileStr.readLine()); } for (int i = 0; i < list.size(); ++i) list.swap(qrand() % list.size(), qrand() % list.size()); foreach (QString itm, list) { if(slideShowPopupAction->isChecked())winPopup->slideTranslationFor( itm ); QEventLoop loop2; QTimer::singleShot(cfg.preferences.slideShowTimer, &loop2, SLOT(quit())); loop2.exec(); } file.close(); }