本文整理汇总了C++中NanoTimer类的典型用法代码示例。如果您正苦于以下问题:C++ NanoTimer类的具体用法?C++ NanoTimer怎么用?C++ NanoTimer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NanoTimer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv) {
checkCommandLine(argc);
vector<int> values;
readFile( argv[1], values );
long total;
NanoTimer nTimer;
nTimer.start();
total = sum( values, atoi(argv[2]) );
nTimer.stop();
display(total, nTimer);
}
示例2: main
int main()
{
DbRetVal rv = OK;
AbsSqlConnection *con = SqlFactory::createConnection(CSql);
rv = con->connect("root", "manager");
if (rv != OK) return 1;
AbsSqlStatement *stmt = SqlFactory::createStatement(CSql);
stmt->setConnection(con);
char statement[1024];
strcpy(statement, "CREATE TABLE t1 (f1 int, f2 char(196));");
int rows =0;
rv = stmt->prepare(statement);
if (rv != OK) {delete stmt; delete con; return -1; }
rv = stmt->execute(rows);
if (rv != OK) {delete stmt; delete con; return -1; }
stmt->free();
printf("Table t1 created\n");
strcpy(statement, "CREATE INDEX t1idx on t1 (f1);");
rv = stmt->prepare(statement);
if (rv != OK) {delete stmt; delete con; return -1; }
rv = stmt->execute(rows);
if (rv != OK) {delete stmt; delete con; return -1; }
stmt->free();
printf("Index created on t1(f1) \n");
strcpy(statement, "INSERT INTO t1 (f1, f2) VALUES (?, ?);");
int id1 =10;
char name[196];
strcpy(name, "Rithish");
NanoTimer timer;
rv = stmt->prepare(statement);
if (rv != OK) {delete stmt; delete con; return -1; }
int count =0;
for (int i = 0 ; i < ITERATIONS ; i++)
{
timer.start();
rv = con->beginTrans();
if (rv != OK) break;
id1 = i;
stmt->setIntParam(1, id1);
strcpy(name, "Gopika");
stmt->setStringParam(2, name);
rv = stmt->execute(rows);
if (rv != OK) break;
rv = con->commit();
if (rv != OK) break;
timer.stop();
count++;
}
printf("Total Rows Inserted %d %lld %lld %lld\n", count, timer.minc(),
timer.maxc(), timer.avg());
stmt->free();
strcpy(statement, "SELECT * FROM t1 where f1 = ?;");
rv = stmt->prepare(statement);
if (rv != OK) {delete stmt; delete con; return -1; }
stmt->bindField(1, &id1);
stmt->bindField(2, name);
timer.reset();
count =0;
for (int i = 0 ; i < ITERATIONS ; i++)
{
timer.start();
rv = con->beginTrans();
if (rv != OK) break;
stmt->setIntParam(1, i);
stmt->execute(rows);
if (stmt->fetch() == NULL) { printf("unable to read record\n"); break; }
stmt->close();
rv = con->commit();
if (rv != OK) break;
timer.stop();
count++;
}
stmt->free();
printf("Total Rows Selected %d %lld %lld %lld\n", count, timer.minc(),
timer.maxc(), timer.avg());
strcpy(statement, "UPDATE t1 set f2=? where f1=?;");
rv = stmt->prepare(statement);
if (rv != OK) {delete stmt; delete con; return -1; }
stmt->bindField(1, &id1);
stmt->bindField(2, name);
timer.reset();
count =0;
for (int i = 0 ; i < ITERATIONS ; i++)
{
timer.start();
rv = con->beginTrans();
if (rv != OK) break;
stmt->setIntParam(2, i);
stmt->setStringParam(1, "ChangedValue");
rv = stmt->execute(rows);
if (rv != OK && rows !=1) break;
rv = con->commit();
if (rv != OK) break;
timer.stop();
count++;
}
//.........这里部分代码省略.........
示例3: main
int main()
{
Connection conn;
DbRetVal rv = conn.open("root", "manager");
if (rv != OK)
{
printf("Error during connection %d\n", rv);
return -1;
}
DatabaseManager *dbMgr = conn.getDatabaseManager();
if (dbMgr == NULL) { printf("Auth failed\n"); return -1;}
TableDef tabDef;
tabDef.addField("f1", typeInt, 0, NULL, true );
tabDef.addField("f2", typeString, 196);
rv = dbMgr->createTable("t1", tabDef);
if (rv != OK) { printf("Table creation failed\n"); return -1; }
printf("Table created\n");
HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
strcpy(idxInfo->tableName, "t1");
idxInfo->list.append("f1");
idxInfo->indType = hashIndex;
if (LOAD >0 )
idxInfo->bucketSize = 100007;
else
idxInfo->bucketSize = 10007;
rv = dbMgr->createIndex("indx1", idxInfo);
if (rv != OK) { printf("Index creation failed\n"); return -1; }
printf("Index created\n");
delete idxInfo;
Table *table = dbMgr->openTable("t1");
if (table == NULL) { printf("Unable to open table\n"); return -1; }
int id = 0;
char name[196] = "PRABAKARAN";
table->bindFld("f1", &id);
table->bindFld("f2", name);
char *tuple;
int ret;
int i;
int icount =0;
if (LOAD > 0) {
TableImpl *impl = (TableImpl*)table;
impl->setUndoLogging(false);
strcpy(name, "PRABAKARAN0123456750590");
rv = conn.startTransaction();
if (rv != OK) exit(1);
for(i = 0; i< LOAD; i++)
{
id= i;
ret = table->insertTuple();
if (ret != 0) break;
icount++;
if (i % 100 == 0 ) { rv = conn.commit();
if (rv != OK) exit(1);
rv = conn.startTransaction();
if (rv != OK) exit(1);
}
if (i %50000 == 0) printf("%d rows inserted\n", i);
}
conn.commit();
impl->setUndoLogging(true);
printf("Loaded %d records\n", icount);
}
//TableImpl *impl = (TableImpl*)table;
//impl->setUndoLogging(false);
i = 0;
NanoTimer timer;
icount =0;
for(i = LOAD; i< LOAD+ITERATIONS; i++)
{
timer.start();
rv = conn.startTransaction();
if (rv != OK) exit(1);
id= i;
strcpy(name, "PRABAKARAN0123456750590");
ret = table->insertTuple();
if (ret != 0) break;
// printf("%d\n ", i);
icount++;
conn.commit();
timer.stop();
}
printf("%d rows inserted %lld %lld %lld\n",icount, timer.minc(), timer.maxc(), timer.avg());
int offset1= os::align(sizeof(int));
Condition p1;
int val1 = 0;
p1.setTerm("f1", OpEquals, &val1);
table->setCondition(&p1);
icount=0;
timer.reset();
for(i = LOAD; i< LOAD+ITERATIONS; i++)
{
timer.start();
rv =conn.startTransaction();
//.........这里部分代码省略.........
示例4: if
//aggregate
long long int aggregate(SQLHANDLE henv, SQLHANDLE hdbc,SQLHANDLE hstmt,int val,bool flag)
{
int summinmax=0,tempTermVar=0;
int rc;
/* Set read-only transaction type */
readOnlyTrans (hdbc);
if(val==1 && flag){
rc = SQLPrepare (hstmt, (unsigned char *) "SELECT MIN(unique1) from big1;", SQL_NTS);
}
else if(val==1 && !flag)
{
rc = SQLPrepare (hstmt, (unsigned char *) "SELECT MIN(unique1) from big1 group by onepercent;", SQL_NTS);
}
else if(val==2 && flag) {
rc = SQLPrepare (hstmt, (unsigned char *) "SELECT MAX(unique1) from big1;", SQL_NTS);
}
else if(val==2 && !flag){
rc = SQLPrepare (hstmt, (unsigned char *) "SELECT MAX(unique1) from big1 group by onepercent;", SQL_NTS);
}
else if(val==3 && flag) {
rc = SQLPrepare (hstmt, (unsigned char *) "SELECT SUM(unique1) from big1;", SQL_NTS);
}
else if(val==3 && !flag){
rc = SQLPrepare (hstmt, (unsigned char *) "SELECT SUM(unique1) from big1 group by onepercent;", SQL_NTS);
}
checkrc (rc, __LINE__);
rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &summinmax, 0, NULL);
checkrc (rc, __LINE__);
int i, j, k;
int Count;
timer.reset ();
for (i = 0; i < 10; i++)
{
timer.start ();
rc = SQLExecute (hstmt);
checkrc (rc, __LINE__);
rc = SQLFetch (hstmt);
checkrc (rc, __LINE__);
Count++;
// printf("value=%d",summin);
rc = SQLCloseCursor (hstmt);
checkrc (rc, __LINE__);
rc = SQLTransact (henv, hdbc, SQL_COMMIT);
checkrc (rc, __LINE__);
timer.stop ();
}
//printf ("Read: 1 %lld\n", timer.avg ());
/* Set read-write transaction type */
readWriteTrans (hdbc);
return timer.avg()/1000;
}
示例5: UpdateTest
//From Prepare to Commit(Update
int UpdateTest(SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt)
{
int rc,i;
int iHolder;
char sHolder[200];
char sData[200];
timer.reset();
for(i=0;i<ITERATION;i++){
timer.start();
rc = SQLPrepare (hstmt,
(unsigned char *) "UPDATE t1 SET f2 = ? WHERE f1 = ?",
SQL_NTS);
checkrc (rc, __LINE__);
SQLINTEGER sLen = SQL_NTS;
rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
196, 0, (void *) sHolder, 0, &sLen);
checkrc (rc, __LINE__);
rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
0, 0, &iHolder, 0, NULL);
checkrc (rc, __LINE__);
iHolder = 0;
strcpy (sData, "9876543210987654321098765432109876543210");
iHolder = i ;
strcpy (sHolder, sData);
rc = SQLExecute (hstmt);
checkrc (rc, __LINE__);
rc = SQLTransact (henv, hdbc, SQL_COMMIT);
checkrc (rc, __LINE__);
timer.stop ();
}
printf ("Update: %lld %lld %lld\n", timer.minc (), timer.maxc (),timer.avg ());
}
示例6: SQLPrepare
int
runDeleteTest (SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt)
{
int rc;
int iHolder;
rc = SQLPrepare (hstmt, (unsigned char *)
"DELETE FROM t1 WHERE f1 = ?", SQL_NTS);
checkrc (rc, __LINE__);
rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
0, 0, &iHolder, 0, NULL);
checkrc (rc, __LINE__);
iHolder = 0;
int i, j, k;
int tCount;
timer.reset ();
/* Run 1per Test */
for (i = START; i < (START+ITERATION); i++)
{
timer.start ();
iHolder = i ;
rc = SQLExecute (hstmt);
checkrc (rc, __LINE__);
rc = SQLTransact (henv, hdbc, SQL_COMMIT);
checkrc (rc, __LINE__);
timer.stop ();
}
printf ("Delete: 1 %lld %lld %lld\n", timer.min (), timer.max (),
timer.avg ());
return 0;
}
示例7: distinct
//DISTINCT
long long int distinct(SQLHANDLE henv, SQLHANDLE hdbc,SQLHANDLE hstmt)
{
int var_onepercent;
int rc;
readOnlyTrans (hdbc);
rc = SQLPrepare (hstmt, (unsigned char *) "SELECT DISTINCT onepercent FROM big1;", SQL_NTS);
checkrc (rc, __LINE__);
rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &var_onepercent, 0, NULL);
checkrc (rc, __LINE__);
int i,count;
timer.reset ();
for (i = 0; i < 10; i++)
{
count=0;
timer.start ();
rc = SQLExecute (hstmt);
checkrc (rc, __LINE__);
while(SQL_SUCCEEDED(rc = SQLFetch(hstmt))){
count++;
}
//checkrc (rc, __LINE__);
rc = SQLCloseCursor (hstmt);
checkrc (rc, __LINE__);
rc = SQLTransact (henv, hdbc, SQL_COMMIT);
checkrc (rc, __LINE__);
timer.stop ();
if (count != 100) {
printf("distinct returned %d rows\n");
readWriteTrans(hdbc);
return 0;
}
}
readWriteTrans(hdbc);
return timer.avg()/1000;
}
示例8: readOnlyTrans
int
runReadTest (SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt)
{
int iHolder;
int second;
char sHolder[200];
char sData[200];
int tempTermVar = 0;
int tempTermVal = 0;
int rc;
/* Set read-only transaction type */
readOnlyTrans (hdbc);
rc = SQLPrepare (hstmt, (unsigned char *)
"SELECT f1, f2 FROM t1 where f1 = ?", SQL_NTS);
checkrc (rc, __LINE__);
long sz = 0;
rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
0, 0, &tempTermVar, 0, NULL);
checkrc (rc, __LINE__);
rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &iHolder, 0, NULL);
checkrc (rc, __LINE__);
rc = SQLBindCol (hstmt, 2, SQL_INTEGER, &second, 0, NULL);
checkrc (rc, __LINE__);
iHolder = 0;
strcpy (sData, "0123456789012345678901234567890123456789");
int i, j, k;
int tCount;
timer.reset ();
/* Run 1per Test */
for (i = START; i < (START+ITERATION); i++)
{
timer.start ();
tempTermVar = i ;
rc = SQLExecute (hstmt);
checkrc (rc, __LINE__);
rc = SQLFetch (hstmt);
checkrc (rc, __LINE__);
tempTermVal = iHolder;
strcpy (sData, sHolder);
rc = SQLCloseCursor (hstmt);
checkrc (rc, __LINE__);
rc = SQLTransact (henv, hdbc, SQL_COMMIT);
checkrc (rc, __LINE__);
timer.stop ();
}
printf ("Read: 1 %lld %lld %lld\n", timer.min (), timer.max (),
timer.avg ());
/* Set read-write transaction type */
readWriteTrans (hdbc);
return rc;
}
示例9: ReadTest
//From Prepare to commit (Read)
int ReadTest(SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt)
{
int iHolder;
char sHolder[200];
char sData[200];
int tempTermVar = 0;
int tempTermVal = 0;
int rc,i;
// Set read-only transaction type
readOnlyTrans (hdbc);
timer.reset();
for(i=0;i<ITERATION;i++){
timer.start();
rc = SQLPrepare (hstmt, (unsigned char *)
"SELECT f1, f2 FROM t1 where f1 = ?", SQL_NTS);
checkrc (rc, __LINE__);
long sz = 0;
rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
0, 0, &tempTermVar, 0, NULL);
checkrc (rc, __LINE__);
rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &iHolder, 0, NULL);
checkrc (rc, __LINE__);
rc = SQLBindCol (hstmt, 2, SQL_C_CHAR, sHolder, sizeof (sHolder), NULL);
checkrc (rc, __LINE__);
iHolder = 0;
strcpy (sData, "0123456789012345678901234567890123456789");
int tCount;
tempTermVar = i ;
rc = SQLExecute (hstmt);
checkrc (rc, __LINE__);
rc = SQLFetch (hstmt);
checkrc (rc, __LINE__);
tempTermVal = iHolder;
strcpy (sData, sHolder);
rc = SQLCloseCursor (hstmt);
checkrc (rc, __LINE__);
rc = SQLTransact (henv, hdbc, SQL_COMMIT);
checkrc (rc, __LINE__);
timer.stop();
}
printf("Select: %lld %lld %lld\n", timer.minc(), timer.maxc(),timer.avg());
readWriteTrans (hdbc);
return rc;
}
示例10: strcpy
int
runInsertTest (SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt)
{
int rc;
int iHolder;
char sHolder[200];
char sData[200];
iHolder = 0;
strcpy (sData, "0123456789012345678901234567890123456789");
rc = SQLPrepare (hstmt, (unsigned char *) "INSERT INTO t1 VALUES (?, ?)",
SQL_NTS);
checkrc (rc, __LINE__);
rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
0, 0, &iHolder, 0, NULL);
checkrc (rc, __LINE__);
SQLINTEGER sLen = SQL_NTS;
rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
196, 0, (void *) sHolder, 0, &sLen);
checkrc (rc, __LINE__);
int i, j, k;
int tCount;
timer.reset ();
/* Run 1per Test */
for (i = 0; i < ITERATION; i++)
{
timer.start ();
iHolder = i ;
strcpy (sHolder, sData);
rc = SQLExecute (hstmt);
checkrc (rc, __LINE__);
rc = SQLTransact (henv, hdbc, SQL_COMMIT);
checkrc (rc, __LINE__);
timer.stop ();
}
printf ("Insert: 1 %lld %lld %lld\n", timer.minc (), timer.maxc (),
timer.avg ());
return 0;
}
示例11: strcpy
int
runInsertTest (SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt)
{
int rc;
int iHolder;
char sHolder[200];
char sData[200];
iHolder = 0;
strcpy (sData, "0123456789012345678901234567890123456789");
rc = SQLPrepare (hstmt, (unsigned char *) "insert into t1 values(?,12,13,14,15,16,17,18,19,20,21,100,100,'AXXXXXXXXXXXXXXXXXXXXXXXXXCXXXXXXXXXXXXXXXXXXXXXXXX','GXXXXXXXXXXXXXXXXXXXXXXXXXCXXXXXXXXXXXXXXXXXXXXXXXXA','OXXXXXXXXXXXXXXXXXXXXXXXXXOXXXXXXXXXXXXXXXXXXXXXXXXO')", SQL_NTS);
checkrc (rc, __LINE__);
rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
0, 0, &iHolder, 0, NULL);
checkrc (rc, __LINE__);
SQLINTEGER sLen = SQL_NTS;
/* rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
196, 0, (void *) sHolder, 0, &sLen);*/
checkrc (rc, __LINE__);
int i, j, k;
int tCount;
timer.reset ();
/* Run 1per Test */
for (i = START; i<(START + ITERATION); i++)
{
timer.start ();
iHolder = i ;
strcpy (sHolder, sData);
rc = SQLExecute (hstmt);
checkrc (rc, __LINE__);
rc = SQLTransact (henv, hdbc, SQL_COMMIT);
checkrc (rc, __LINE__);
timer.stop ();
}
printf ("Insert: 1 %lld %lld %lld\n", timer.min (), timer.max (),
timer.avg ());
return 0;
}
示例12: joinCondition
long long int joinCondition(SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt,int value)
{
int uni1;
int uni2,uni3,uni4,uni5;
char str1[52];
char str2[52];
int rc;
int searchVal[] = {1, 5, 10, 50, 100, 200, 250, 500, 750, 800};
//Set read-only transaction type
readOnlyTrans (hdbc);
if(value==1 )
{
rc = SQLPrepare (hstmt, (unsigned char *) "SELECT big1.unique1, big1.unique2, small.unique1, small.stringu1 FROM big1,small WHERE big1.unique1=small.unique1 AND big1.unique1 > ? and big1.unique1 <= ?;", SQL_NTS);
}
else {
rc = SQLPrepare (hstmt, (unsigned char *) "SELECT small.unique1, big1.unique1, big2.unique1, small.stringu1, big1.unique2, big2.unique2 FROM big1, big2, small WHERE big1.unique1=small.unique1 AND big1.unique1=big2.unique1 AND big1.unique1 > ? and big1.unique1 <= ?;", SQL_NTS);
}
checkrc (rc, __LINE__);
int tempTermVar1 =0, tempTermVar2=0;
rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar1, 0, NULL);
checkrc (rc, __LINE__);
rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar2, 0, NULL);
checkrc (rc, __LINE__);
long sz = 0;
rc = SQLBindCol (hstmt, 1, SQL_C_SLONG, &uni1, 0, NULL);
checkrc (rc, __LINE__);
rc = SQLBindCol (hstmt, 2, SQL_C_SLONG, &uni2, 0, NULL);
checkrc (rc, __LINE__);
rc = SQLBindCol (hstmt, 3, SQL_C_SLONG, &uni3, 0, NULL);
checkrc (rc, __LINE__);
rc = SQLBindCol (hstmt, 4, SQL_C_CHAR, str1, sizeof (str1), NULL);
checkrc (rc, __LINE__);
if(value==2){
rc = SQLBindCol (hstmt, 5, SQL_C_SLONG, &uni4, 0, NULL);
checkrc (rc, __LINE__);
rc = SQLBindCol (hstmt, 6, SQL_C_SLONG, &uni5, 0, NULL);
checkrc (rc, __LINE__);
}
int i, j, k;
int count=0;
timer.reset ();
for(i=0;i<10;i++){
count=0;
tempTermVar1 = searchVal[i];
tempTermVar2 = searchVal[i]+100;
timer.start ();
rc = SQLExecute (hstmt);
checkrc (rc, __LINE__);
while(SQL_SUCCEEDED(rc = SQLFetch(hstmt)))
{
count++;
//printf("Uni1:%d uni2=%d uni3=%d \n",uni1,uni2,uni3);
}
rc = SQLCloseCursor (hstmt);
checkrc (rc, __LINE__);
rc = SQLTransact (henv, hdbc, SQL_COMMIT);
checkrc (rc, __LINE__);
timer.stop ();
if (count != 100) {
printf ("range join returned %d rows\n", count);
readWriteTrans (hdbc);
return 0;
}
}
readWriteTrans (hdbc);
return timer.avg()/1000;
}
示例13: joining
//Joining
long long int joining(SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt,int value)
{
int uni1;
int uni2,uni3,uni4,uni5;
char str1[52];
char str2[52];
int val[10] = {1, 5, 10, 50, 100, 250, 500, 750, 900, 999};
int tempTermVar=0;
char tempval[124]="Value";
int rc;
/* Set read-only transaction type */
readOnlyTrans (hdbc);
if(value==1 ){
rc = SQLPrepare (hstmt, (unsigned char *) "SELECT big1.unique1, big1.unique2, small.unique1, small.stringu1 FROM big1,small WHERE big1.unique1=small.unique1 AND big1.unique1=?;", SQL_NTS);
}
else {
rc = SQLPrepare (hstmt, (unsigned char *) "SELECT small.unique1, big1.unique1, big2.unique1, small.stringu1, big1.unique2, big2.unique2 FROM big1, big2, small WHERE small.unique1=big1.unique2 AND big1.unique2=big2.unique1 AND big1.unique1 = ?;", SQL_NTS);
}
checkrc (rc, __LINE__);
long sz = 0;
rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar, 0, NULL);
checkrc (rc, __LINE__);
rc = SQLBindCol (hstmt, 1, SQL_C_LONG, &uni1, 0, NULL);
checkrc (rc, __LINE__);
rc = SQLBindCol (hstmt, 2, SQL_C_LONG, &uni2, 0, NULL);
checkrc (rc, __LINE__);
rc = SQLBindCol (hstmt, 3, SQL_C_LONG, &uni3, 0, NULL);
checkrc (rc, __LINE__);
rc = SQLBindCol (hstmt, 4, SQL_C_CHAR, str1, sizeof (str1), NULL);
checkrc (rc, __LINE__);
if(value==2 ){
rc = SQLBindCol (hstmt, 5, SQL_C_LONG, &uni4, 0, NULL);
checkrc (rc, __LINE__);
rc = SQLBindCol (hstmt, 6, SQL_C_LONG, &uni5, 0, NULL);
checkrc (rc, __LINE__);
}
int i, j, k;
int Count=0;
timer.reset ();
for (i = 0; i < 10; i++)
{
tempTermVar = val[i];
timer.start ();
rc = SQLExecute (hstmt);
checkrc (rc, __LINE__);
rc=SQLFetch(hstmt);
Count++;
rc = SQLCloseCursor (hstmt);
checkrc (rc, __LINE__);
rc = SQLTransact (henv, hdbc, SQL_COMMIT);
checkrc (rc, __LINE__);
timer.stop ();
// printf("uni1=%d uni2=%d uni3=%d str1=%s \n",uni1,uni2,uni3,str1);
}
readWriteTrans (hdbc);
return timer.avg()/1000;
}
示例14: SQLConnect
int
runReadTest (SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt)
{
int iHolder;
char sHolder[200];
char sData[200];
int tempTermVar = 0;
int tempTermVal = 0;
int rc,i;
timer.reset();
for(i=0;i<ITERATION;i++){
timer.start();
rc = SQLConnect (hdbc,
(SQLCHAR *) DSN, SQL_NTS,
(SQLCHAR *) "root",
(SQLSMALLINT) strlen ("root"),
(SQLCHAR *) "manager",
(SQLSMALLINT) strlen (""));
if (SQL_SUCCEEDED(rc)) {
if (rc == SQL_SUCCESS_WITH_INFO) {
printf("Driver reported the following diagnostics\n");
extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC);
}
}else {
fprintf(stderr, "Failed to connect\n");
extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC);
}
//check_error (SQL_HANDLE_DBC, hdbc, rc, __LINE__);
checkrc (rc, __LINE__);
rc = SQLSetConnectOption (hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF);
checkrc (rc, __LINE__);
rc = SQLAllocHandle (SQL_HANDLE_STMT, hdbc, &hstmt);
checkrc (rc, __LINE__);
// Set read-only transaction type
readOnlyTrans (hdbc);
rc = SQLPrepare (hstmt, (unsigned char *)
"SELECT f1, f2 FROM t1 where f1 = ?", SQL_NTS);
checkrc (rc, __LINE__);
long sz = 0;
rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
0, 0, &tempTermVar, 0, NULL);
checkrc (rc, __LINE__);
rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &iHolder, 0, NULL);
checkrc (rc, __LINE__);
rc = SQLBindCol (hstmt, 2, SQL_C_CHAR, sHolder, sizeof (sHolder), NULL);
checkrc (rc, __LINE__);
iHolder = 0;
strcpy (sData, "0123456789012345678901234567890123456789");
int tCount;
tempTermVar = i ;
rc = SQLExecute (hstmt);
checkrc (rc, __LINE__);
rc = SQLFetch (hstmt);
checkrc (rc, __LINE__);
tempTermVal = iHolder;
strcpy (sData, sHolder);
rc = SQLCloseCursor (hstmt);
checkrc (rc, __LINE__);
rc = SQLTransact (henv, hdbc, SQL_COMMIT);
checkrc (rc, __LINE__);
rc = SQLFreeHandle (SQL_HANDLE_STMT, hstmt);
checkrc (rc, __LINE__);
rc = SQLDisconnect (hdbc);
checkrc (rc, __LINE__);
timer.stop();
}
printf("Select: %lld %lld %lld\n", timer.minc(), timer.maxc(),timer.avg());
return rc;
}
示例15: orderBy
long long int orderBy(SQLHANDLE henv, SQLHANDLE hdbc,SQLHANDLE hstmt)
{
int val[] = {1, 5, 10, 50, 100, 500, 1000, 5000 ,7500, 9500};
int var_two, var_four, var_ten, var_twenty, var_onepercent;
char str1[52];
int tempTermVar=0, tempTermVar2=0, tempTermVar3=0;
int rc;
rc = SQLPrepare (hstmt, (unsigned char *) "SELECT two, four, ten, twenty, onepercent, string4 from big1 where unique1 between ? and ? order by unique1;", SQL_NTS);
checkrc (rc, __LINE__);
readOnlyTrans (hdbc);
rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar, 0, NULL);
checkrc (rc, __LINE__);
rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar2, 0, NULL);
checkrc (rc, __LINE__);
rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &var_two, 0, NULL);
checkrc (rc, __LINE__);
rc = SQLBindCol (hstmt, 2, SQL_INTEGER, &var_four, 0, NULL);
checkrc (rc, __LINE__);
rc = SQLBindCol (hstmt, 3, SQL_INTEGER, &var_ten, 0, NULL);
checkrc (rc, __LINE__);
rc = SQLBindCol (hstmt, 4, SQL_INTEGER, &var_twenty, 0, NULL);
checkrc (rc, __LINE__);
rc = SQLBindCol (hstmt, 5, SQL_INTEGER, &var_onepercent, 0, NULL);
checkrc (rc, __LINE__);
rc = SQLBindCol (hstmt, 6, SQL_C_CHAR, str1, sizeof (str1), NULL);
checkrc (rc, __LINE__);
int i, j, k;
int count;
timer.reset ();
for (i = 0; i < 10; i++)
{
count=0;
tempTermVar=val[i];
tempTermVar2 = val[i]+100 ;
timer.start ();
rc = SQLExecute (hstmt);
checkrc (rc, __LINE__);
rc = SQLFetch (hstmt);
while(SQL_SUCCEEDED(rc = SQLFetch(hstmt))) count++;
//checkrc (rc, __LINE__);
rc = SQLCloseCursor (hstmt);
checkrc (rc, __LINE__);
rc = SQLTransact (henv, hdbc, SQL_COMMIT);
checkrc (rc, __LINE__);
timer.stop ();
if (count != 100) {
printf("orderby returned %d rows \n", count);
readWriteTrans(hdbc);
return 0;
}
}
readWriteTrans(hdbc);
return timer.avg()/1000;
}