;========================================================================================================================================== ; Profiling how to read/write RGB value from/to AskColor inifile. ; ; This profiling loop includes five slightly different coding algorithms ; how to read/write a RGB value from/to inifile using the AskColor function. ; ; Note: The test loop requires that the AskColor dialog and the write operations to the inifile are disabled. ; For normal use of a code variant do activate the three disabled lines (delete the comment char). ; ; Detlev Dalitz.20090417. ;========================================================================================================================================== ;Goto RunDialogsOnce ; Run each dialog once and exit. ; Which tests to check. strListTests = "1,2,3,4,5" ; How many loops to run. intLoopMax = 1000 ; Loop. BoxOpen ("Test", "Be patient ...") intTestMin = 1 intTestMax = ItemCount (strListTests, ",") For intItem = intTestMin To intTestMax intTest = ItemExtract (intItem, strListTests, ",") intTicks%intTest% = 0 For intLoop = 1 To intLoopMax strMsgText = "Test: " : intTestMax : "/" : intTest : @LF : "Loop: " : intLoopMax : "/" : intLoop : @LF : "Ticks%intTest%: " : intTicks%intTest% BoxText (strMsgText) Exclusive (@ON) intTicksStart = GetTickCount () GoSub Test%intTest% intTicksStop = GetTickCount () Exclusive (@OFF) intTicks%intTest% = intTicks%intTest% + intTicksStop - intTicksStart Next BoxText (strMsgText) Next BoxShut () ; Result. Decimals (0) intTicksSum = 1 ; To prevent dividing by zero. For intTest = intTestMin To intTestMax intTicksSum = intTicksSum + intTicks%intTest% Next For intTest = intTestMin To intTestMax intPct%intTest% = 100.0 * intTicks%intTest% / intTicksSum Next ; Format output; strTest = "Test" strTicks = "Ticks" strPct = "Pct" strSep = " " strPre = "; " intLenTest = Max (StrLen (strTest), StrLen (intTestMax)) intLenTicks = StrLen (strTicks) intLenPct = StrLen (strPct) For intItem = intTestMin To intTestMax intTest = ItemExtract (intItem, strListTests, ",") intLenTicks = Max (intLenTicks, StrLen (intTicks%intTest%)) intLenPct = Max (intLenPct, StrLen (intPct%intTest%)) Next strTest = StrFixLeft (strTest, " ", intLenTest) strTicks = StrFixLeft (strTicks, " ", intLenTicks) strPct = StrFixLeft (strPct, " ", intLenPct) strResult = "" strResult = ItemInsert (StrCat (strPre, "Iterations: ", intLoopMax), -1, strResult, @LF) strResult = ItemInsert (StrCat (strPre, strTest, strSep, strTicks, strSep, strPct), -1, strResult, @LF) For intTest = intTestMin To intTestMax strTest = StrFixLeft (intTest, " ", intLenTest) strTicks = StrFixLeft (intTicks%intTest%, " ", intLenTicks) strPct = StrFixLeft (intPct%intTest%, " ", intLenPct) strResult = ItemInsert (StrCat (strPre, strTest, strSep, strTicks, strSep, strPct), -1, strResult, @LF) Next strResult = StrCat (strResult, @LF) Message ("Test Result", strResult) ClipPut (strResult) Exit ;------------------------------------------------------------------------------------------------------------------------------------------ ; GoSub's. ;------------------------------------------------------------------------------------------------------------------------------------------ :Test1 strRGB = IniReadPvt ("StudioHints", "ColorVarLabel", "", "www-prod.ini") hdlBB = BinaryAlloc (3) BinaryPoke (hdlBB, 0, ItemExtract (1, strRGB, ",")) BinaryPoke (hdlBB, 1, ItemExtract (2, strRGB, ",")) BinaryPoke (hdlBB, 2, ItemExtract (3, strRGB, ",")) strHex = "#" : BinaryPeekHex (hdlBB, 0, 3) ;strRGB = AskColor (strHex, "", 1) ;strRGB = StrReplace (strRGB, "|", ",") ;IniWritePvt ("StudioHints", "ColorVarLabel", strRGB, "www-prod.ini") hdlBB = BinaryFree (hdlBB) Drop (strHex, hdlBB, strRGB) Return ;------------------------------------------------------------------------------------------------------------------------------------------ :Test2 strRGB = IniReadPvt ("StudioHints", "ColorVarLabel", "", "www-prod.ini") intDec = ItemExtract (1, strRGB, ",") | ItemExtract (2, strRGB, ",") << 8 | ItemExtract (3, strRGB, ",") << 16 hdlBB = BinaryAlloc (4) BinaryPoke4 (hdlBB, 0, intDec) strHex = "#" : BinaryPeekHex (hdlBB, 0, 3) ;strRGB = AskColor (strHex, "", 1) ;strRGB = StrReplace (strRGB, "|", ",") ;IniWritePvt ("StudioHints", "ColorVarLabel", strRGB, "www-prod.ini") hdlBB = BinaryFree (hdlBB) Drop (strHex, hdlBB, intDec, strRGB) Return ;------------------------------------------------------------------------------------------------------------------------------------------ :Test3 strRGB = IniReadPvt ("StudioHints", "ColorVarLabel", "", "www-prod.ini") intR = ItemExtract (1, strRGB, ",") intG = ItemExtract (2, strRGB, ",") intB = ItemExtract (3, strRGB, ",") strHex = "#" : Num2Char ((intR >> 4) + 48 + 7 * ((intR >> 4) > 9)) : Num2Char ((intR & 15) + 48 + 7 * ((intR & 15) > 9)) : Num2Char ((intG >> 4) + 48 + 7 * ((intG >> 4) > 9)) : Num2Char ((intG & 15) + 48 + 7 * ((intG & 15) > 9)) : Num2Char ((intB >> 4) + 48 + 7 * ((intB >> 4) > 9)) : Num2Char ((intB & 15) + 48 + 7 * ((intB & 15) > 9)) ;strRGB = AskColor (strHex, "", 1) ;strRGB = StrReplace (strRGB, "|", ",") ;IniWritePvt ("StudioHints", "ColorVarLabel", strRGB, "www-prod.ini") Drop (strHex, intB, intG, intR, strRGB) Return ;------------------------------------------------------------------------------------------------------------------------------------------ :Test4 AddExtender ("wilx44i.dll") strRGB = IniReadPvt ("StudioHints", "ColorVarLabel", "", "www-prod.ini") intDec = ItemExtract (3, strRGB, ",") | ItemExtract (2, strRGB, ",") << 8 | ItemExtract (1, strRGB, ",") << 16 strHex = "#" : StrFixLeft (xBaseConvert (intDec, 10, 16), "0", 6) ;strRGB = AskColor (strHex, "", 1) ;strRGB = StrReplace (strRGB, "|", ",") ;IniWritePvt ("StudioHints", "ColorVarLabel", strRGB, "www-prod.ini") Drop (strHex, intDec, strRGB) Return ;------------------------------------------------------------------------------------------------------------------------------------------ :Test5 strRGB = IniReadPvt ("StudioHints", "ColorVarLabel", "", "www-prod.ini") intDec = ItemExtract (3, strRGB, ",") | ItemExtract (2, strRGB, ",") << 8 | ItemExtract (1, strRGB, ",") << 16 strHex = "" intZ = 1 For intI = 7 To 0 By -1 intN = (intDec >> (intI * 4)) & 15 If !intN Then If intZ Then Continue intZ = 0 strHex = StrCat (strHex, StrSub ("0123456789ABCDEF", intN + 1, 1)) Next strHex = "#" : StrFixLeft (strHex, "0", 6) ;strRGB = AskColor (strHex, "", 1) ;strRGB = StrReplace (strRGB, "|", ",") ;IniWritePvt ("StudioHints", "ColorVarLabel", strRGB, "www-prod.ini") Drop (intN, intI, intZ, strHex, intDec, strRGB) Return ;------------------------------------------------------------------------------------------------------------------------------------------ ; The test results are different. ;------------------------------------------------------------------------------------------------------------------------------------------ ; Iterations: 1000 ; Test Ticks Pct ; 1 936 11 ; This may be the winner. ; 2 1066 13 ; 3 1207 14 ; 4 1304 15 ; 5 4012 47 ;------------------------------------------------------------------------------------------------------------------------------------------ ; Iterations: 1000 ; Test Ticks Pct ; 1 970 33 ; 2 983 33 ; 3 1028 34 ;========================================================================================================================================== ;========================================================================================================================================== :RunDialogsOnce ; How to read/write a RGB value from/to inifile using the AskColor function. ;------------------------------------------------------------------------------------------------------------------------------------------ ; Method-1 strRGB = IniReadPvt ("StudioHints", "ColorVarLabel", "", "www-prod.ini") hdlBB = BinaryAlloc (3) BinaryPoke (hdlBB, 0, ItemExtract (1, strRGB, ",")) BinaryPoke (hdlBB, 1, ItemExtract (2, strRGB, ",")) BinaryPoke (hdlBB, 2, ItemExtract (3, strRGB, ",")) strHex = "#" : BinaryPeekHex (hdlBB, 0, 3) strRGB = AskColor (strHex, "", 1) strRGB = StrReplace (strRGB, "|", ",") IniWritePvt ("StudioHints", "ColorVarLabel", strRGB, "www-prod.ini") hdlBB = BinaryFree (hdlBB) Drop (strHex, hdlBB, strRGB) ;------------------------------------------------------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------------------------------------------------------ ; Method-2 strRGB = IniReadPvt ("StudioHints", "ColorVarLabel", "", "www-prod.ini") intDec = ItemExtract (1, strRGB, ",") | ItemExtract (2, strRGB, ",") << 8 | ItemExtract (3, strRGB, ",") << 16 hdlBB = BinaryAlloc (4) BinaryPoke4 (hdlBB, 0, intDec) strHex = "#" : BinaryPeekHex (hdlBB, 0, 3) strRGB = AskColor (strHex, "", 1) strRGB = StrReplace (strRGB, "|", ",") IniWritePvt ("StudioHints", "ColorVarLabel", strRGB, "www-prod.ini") hdlBB = BinaryFree (hdlBB) Drop (strHex, hdlBB, intDec, strRGB) ;------------------------------------------------------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------------------------------------------------------ ; Method-3 strRGB = IniReadPvt ("StudioHints", "ColorVarLabel", "", "www-prod.ini") intR = ItemExtract (1, strRGB, ",") intG = ItemExtract (2, strRGB, ",") intB = ItemExtract (3, strRGB, ",") strHex = "#" : Num2Char ((intR >> 4) + 48 + 7 * ((intR >> 4) > 9)) : Num2Char ((intR & 15) + 48 + 7 * ((intR & 15) > 9)) : Num2Char ((intG >> 4) + 48 + 7 * ((intG >> 4) > 9)) : Num2Char ((intG & 15) + 48 + 7 * ((intG & 15) > 9)) : Num2Char ((intB >> 4) + 48 + 7 * ((intB >> 4) > 9)) : Num2Char ((intB & 15) + 48 + 7 * ((intB & 15) > 9)) strRGB = AskColor (strHex, "", 1) strRGB = StrReplace (strRGB, "|", ",") IniWritePvt ("StudioHints", "ColorVarLabel", strRGB, "www-prod.ini") Drop (strHex, intB, intG, intR, strRGB) ;------------------------------------------------------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------------------------------------------------------ ; Method-4 AddExtender ("wilx44i.dll") strRGB = IniReadPvt ("StudioHints", "ColorVarLabel", "", "www-prod.ini") intDec = ItemExtract (3, strRGB, ",") | ItemExtract (2, strRGB, ",") << 8 | ItemExtract (1, strRGB, ",") << 16 strHex = "#" : StrFixLeft (xBaseConvert (intDec, 10, 16), "0", 6) strRGB = AskColor (strHex, "", 1) strRGB = StrReplace (strRGB, "|", ",") IniWritePvt ("StudioHints", "ColorVarLabel", strRGB, "www-prod.ini") Drop (strHex, intDec, strRGB) ;------------------------------------------------------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------------------------------------------------------ ; Method-5 strRGB = IniReadPvt ("StudioHints", "ColorVarLabel", "", "www-prod.ini") intDec = ItemExtract (3, strRGB, ",") | ItemExtract (2, strRGB, ",") << 8 | ItemExtract (1, strRGB, ",") << 16 strHex = "" intZ = 1 For intI = 7 To 0 By -1 intN = (intDec >> (intI * 4)) & 15 If !intN Then If intZ Then Continue intZ = 0 strHex = StrCat (strHex, StrSub ("0123456789ABCDEF", intN + 1, 1)) Next strHex = "#" : StrFixLeft (strHex, "0", 6) strRGB = AskColor (strHex, "", 1) strRGB = StrReplace (strRGB, "|", ",") IniWritePvt ("StudioHints", "ColorVarLabel", strRGB, "www-prod.ini") Drop (intN, intI, intZ, strHex, intDec, strRGB) ;------------------------------------------------------------------------------------------------------------------------------------------ Exit ;==========================================================================================================================================