I am trying to compare the speed of dbf(cdx/ntx/ads) with adordd. I want to improve the speed of adordd, but before that I should know what the current situation is exactly. Therefor I made a little testapp, especially to compare the DbSeek function for dbf and adordd.
Is there a way to count the duration more precisely? Now sometimes it gives 0.00 (with dbf).
I am using something like this:
Code: Select all | Expand
nsecs := Seconds()USE LargeDbfduration1 := Seconds() - nsecmemowrit("log.txt", Memoread("log.txt") + "|" + "USE LargeDbf: " + str(duration1)
I have also tested MsgInfo( 5 / 0 ) which gives 0. I think this should give an error.
Code: Select all | Expand
#include "Adordd.ch"#include "adodef.ch"static oCnPROCEDURE Main()//createLargeDbfFile()//ConvertDbf()array1Dbf := RunDbSeekTest(.F.,10000)array2Ado := RunDbSeekTest(.T.,10000)DbfTimesFasterThanAdorddUse := array2Ado[1] / array1Dbf[1]DbfTimesFasterThanAdorddIndex := array2Ado[2] / array1Dbf[2]DbfTimesFasterThanAdorddDBSEEK := array2Ado[3] / array1Dbf[3]DbfTimesFasterThanAdorddAVDBSEEK := array2Ado[4] / array1Dbf[4] memowrit("log.txt",MemoRead("log.txt") + " " + "DbfTimesFasterThanAdorddUse: " + str(DbfTimesFasterThanAdorddUse) + " " + "DbfTimesFasterThanAdorddIndex: " + str(DbfTimesFasterThanAdorddIndex) + " " + "DbfTimesFasterThanAdorddDBSEEK: " + str(DbfTimesFasterThanAdorddDBSEEK) + " " + "DbfTimesFasterThanAdorddAVDBSEEK: " + str(DbfTimesFasterThanAdorddAVDBSEEK) )RETURNFUNCTION RunDbSeekTest(bSQL, numberOfLoop)memowrit("log.txt",MemoRead("log.txt") + "Begin DbSeek=" + "SQL: " + IF(bSQL, "TRUE", "FALSE") + "|numberOfLoop: " + str(numberOfLoop) + " ")IF bSQL//MsgInfo( ADOVERSION() )******REQUEST ADORDDRddRegister("ADORDD",1)RddSetDefault("ADORDD")SET ADO FORCE LOCK OFF // Required!SET ADO DEFAULT DATABASE TO "dbseekdb" SERVER TO "localhost" ENGINE TO "MYSQL" USER TO "pieter" PASSWORD TO "password"SET ADO TEMPORAY NAMES INDEX LIST TO {"TMP","TEMP"}SET ADO DEFAULT RECNO FIELD TO "HBRECNO"SET ADO DEFAULT DELETED FIELD TO "HBDELETED"SET ADODBF TABLES INDEX LIST TO { {"LARGEDBF", {"CO1", "COLUMN1"}, {"CO2", "COLUMN2"}}}SET AUTOPEN ONELSEREQUEST DBFCDXRddRegister("DBFCDX",1)RddSetDefault("DBFCDX")ENDIFnsecs := Seconds()USE LargeDbfduration1 := Seconds() - nsecsmemowrit("log.txt", Memoread("log.txt") + "|" + "USE LargeDbf: " + str(duration1))nsecs := Seconds()INDEX ON COLUMN1 TO LargeDbfduration2 := Seconds() - nsecsmemowrit("log.txt", Memoread("log.txt") + "|" + "INDEX ON COLUMN1 TO LargeDbf: " + str(duration2))nsecs := Seconds()FOR i:= 1 TO numberOfLoop DBSEEK(numberOfLoop / 2) NEXTduration3 := Seconds() - nsecsmemowrit("log.txt", Memoread("log.txt") + "|" + "FOR DBSEEK Duration: " + str(duration3))AverageDuration := duration3 / numberOfLoop memowrit("log.txt", Memoread("log.txt") + "|" + "Average DBSEEK Duration: " + str(AverageDuration))RETURN {duration1, duration2, duration3, AverageDuration }FUNCTION createLargeDbfFile()Create StructureLargeDbfAPPEND BLANKFIELD->FIELD_NAME := "Column1"FIELD->FIELD_TYPE := "N"FIELD->FIELD_LEN := 8FIELD->FIELD_DEC := 0FOR i:=2 TO 20 APPEND BLANK ts := ALLTRIM(STR(i,8)) FIELD->FIELD_NAME := "Column" + ts FIELD->FIELD_TYPE := "C" FIELD->FIELD_LEN := 20 FIELD->FIELD_DEC := 0NEXTCLOSECREATE LargeDbf FROM StructureLargeDbfFOR j:=1 TO 20000 APPEND BLANK FOR x := 1 TO 20 IF x = 1 REPLACE Column1 WITH j ELSE ts := ALLTRIM(STR(x,3)) ts2 := ALLTRIM(STR(HB_RandomInt(1000),5)) ts3 := "Column" + ts ts4 := "td" + ts2 REPLACE &ts3 WITH ts4 ENDIF NEXTNEXTCLOSERETURN NILfunction ConvertDbf() CreateDatabaseIfNotYetExist( "dbseekdb" ) ConnectWithDatabase( "dbseekdb" ) FW_AdoImportFromDBF( oCn, "C:\Pieter\LeerOmgevingHarbour\DbSeek\largedbf.dbf", "largedbf")RETURN//----------------------------------------------------------------------------//FUNCTION CloseDatabase() oCn:Close()RETURN NIL FUNCTION ConnectWithDatabase( vardb ) ADOCONNECT oCn TO MYSQL SERVER localhost DATABASE &vardb USER pieter PASSWORD "password" // PASSWORD ... if oCn == nil .or. oCn:State < 1 MsgInfo( "Connect failed" ) return nil endif //MsgInfo( "Connection Open" )RETURN NIL FUNCTION CreateDatabaseIfNotYetExist( vardb ) local oError ADOCONNECT oCn TO MYSQL SERVER localhost USER pieter PASSWORD password if oCn == nil MsgInfo( "Not connected" ) else if oCn:State > 0 //MsgInfo( "open" ) TRY oCn:Execute( "CREATE DATABASE " + vardb ) //MsgInfo( "created" ) CATCH oError MsgInfo( "The database already exists" ) END else MsgInfo( "not open" ) endif endif oCn:Close() Return nil
Pieter