How does Qt read the database more slowly than C #? It seems I'm missing something! To compare read speed, I wrote the following in Qt
QElapsedTimer t; t.start(); int count = 0; QString cs = "Driver={SQL Server}; Server=EMON;Database=FAODB;User=Test;Password=Test"; QSqlDatabase db = QSqlDatabase::addDatabase("QODBC",cs); db.setDatabaseName(cs); db.open(); QSqlQuery query(db); query.setForwardOnly(true); query.exec("SELECT * FROM FAOCropsLivestock"); while(query.next()){ if(query.value("Country").toString() == "\"Bangladesh\"") count++; } db.close(); qDebug()<< QString::number(count) + " elapsed ms " + QString::number(t.elapsed());
and in c #
Stopwatch s = new Stopwatch(); s.Start(); int count = 0; string cs = ConfigurationManager.ConnectionStrings["DB"].ConnectionString; string query = "SELECT * FROM FAOCropsLivestock"; using(SqlConnection con = new SqlConnection(cs)){ using(SqlCommand cmd = new SqlCommand(query, con)){ con.Open(); SqlDataReader rd = cmd.ExecuteReader(); while (rd.Read()){ if(rd["Country"].ToString() == "\"Bangladesh\"") count++; } } } s.Stop(); Console.WriteLine(count + " elapsed ms " + s.ElapsedMilliseconds);
Both C # and Qt are for x86 and Release mode.
In the case of Qt, the result was "63653 elapsed ms 68213" and in C # "63653 elapsed ms 14210"
For the Qt version, I replaced
QString cs = "Driver={SQL Server}; Server=EMON;Database=FAODB;User=Test;Password=Test"; QSqlDatabase db = QSqlDatabase::addDatabase("QODBC",cs); db.setDatabaseName(cs);
by
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC" ); db.setDatabaseName("Driver={SQL Server Native Client 11.0};"\ "Server=EMON;Database=FAODB;Uid=Test;Pwd=Test;");
The results were between 58 s - 71 s.
source share