分类: C/C++
2008-04-23 21:36:45
C#和C 的速度大比拼(第二部分)
编译:
CREATE TABLE testtable ( col1 INTEGER, col2 VARCHAR(50), PRIMARY KEY (col1) )
代码五:db.cpp #import "msado15.dll" \ no_namespace rename("EOF", "EndOfFile") #include#include #include int main(int argc, char* argv[]) { if (argc != 2) { std::cerr << "Usage:\tdb [rows]\n"; return 1; }; ::CoInitialize(NULL); int NUM = atoi(argv[1]); DWORD dw = ::GetTickCount(); _ConnectionPtr conptr(__uuidof(Connection)); conptr->Open(L"Provider=Microsoft.Jet.OLEDB.4.0;" "Data Source=c:\\db.mdb;", L"", L"", adOpenUnspecified); for (int i=0;i Execute(sql, &RecordsEffected, adCmdText); }; DWORD dw2 = ::GetTickCount(); std::cout << "Milliseconds = " << dw2-dw << std::endl; dw = ::GetTickCount(); for (int j=0;j<100;j ) { _RecordsetPtr rsptr(__uuidof(Recordset)); rsptr->Open(L"SELECT col1, col2 FROM testtable", conptr.GetInterfacePtr(), adOpenForwardOnly, adLockOptimistic, adCmdText); while (rsptr->EndOfFile) { _variant_t v1 = rsptr->GetCollect("col1"); _variant_t v2 = rsptr->GetCollect("col2"); rsptr->MoveNext(); }; rsptr->Close(); }; dw2 = ::GetTickCount(); std::cout << "Milliseconds = " << dw2-dw << std::endl; dw = ::GetTickCount(); for (int i=0;i 下表为运行十次,每次100行记录的结果 表三:数据库测试结果
序号 给主人留下些什么吧!~~
|