Unsolved File Searching operation taking more time using qt
-
Hi all,
In my device, 500 files are in database.
In our application, we search file from 500 files.
Suppose same file name have upto 200 files ,we observed that searching operation consuming more time.
Could you please let me know why its taking more time.
ThanksI
-
Hard to say with the information provided. More information would be needed:
- Files are in a database. What kind of database?
- Are there contents or perhaps just filenames?
- How do you do the searching? Your Qt code?
- Consumes more time compared with what other method?
- How much more is "more time"? Millisecond? 10 percent? Ten times?
- Your device, its characteristics, OS, Qt version?
-
I am using Linux and 4.4.3 qt version for arm processor.
Processor frequency is 200Mhz.
Following is code snippest:
foreach(QString patientIdStr, m_patientList)
{
if (patientIdStr.startsWith(ui->editSearch->text()))
{
QString patientId = patientIdStr.section('_', 1, 1);testReportIds = CDatabaseManager::instance()->GetTestReportIdsWithPatient(patientId); if (!testReportIds.isEmpty()) { for (int index = 0; index < testReportIds.count(); index++) { m_testReportList.append(testReportIds.at(index)); patientIds.append(patientIdStr); } } else { m_testReportList.append(""); patientIds.append(patientIdStr); } } }
In this , its searches entered letter with existing files.
Suppose 194 patient name which is start with letter "C" are present in database.
The above code taking around 150 sec to serach patient Id for 194 patient from existing database.Can you explain how foreach works.
Is any other alternative to make fast search. -
Hi,
Not everything comes from that but your code is not the most efficient.
For example:
- patientIdStr, the way you wrote it, you create a copy at each iteration rather than using a const reference thus time and memory consuming.
- your startsWith call, again, each iteration you retrieve the text from editSearch which is a waste of time, retrieve it once before starting the loop.
- Why are you calling append m_testReportList.append once of each item in testReportIds ? You can do it in one call.
- Why are you calling
patientIds.append(patientIdStr);
the same number of times you have testReportIds ?
-
Can u suggest how to break foreach loop
-
What do you mean by "break foreach loop" ?