Modify

Opened 8 years ago

Last modified 10 months ago

#2370 assigned Feature Request

StringReplace & StringRegExpReplace Add Offset\The starting position of the search

Reported by: anonymous Owned by: Jpm
Milestone: Component: AutoIt
Version: Severity: None
Keywords: Cc:

Description

would be very useful to add the "Offset\The starting position of the search" in StringReplace\StringRegExpReplace to work much more faster with strings

it seems that in xxx works really well and quickly, instead ddd does not work well in almost as if it does not work at all

Local $sFileData, $iString, $iTimerDiff

$sFileData =  FileRead(@DesktopDir& "\test.ini") ; test.ini = 10 Mb - includes inside, the string TestXXXX

$iTimerDiff = TimerInit()
$iString = StringInStr($sFileData, "TestXXXX", 1, 1, 2767600)
$iTimerDiff = TimerDiff($iTimerDiff)
ConsoleWrite($iString & " - " & $iTimerDiff & @LF)

$iTimerDiff = TimerInit()
$iString = StringRegExp($sFileData, "TestXXXX")
$iTimerDiff = TimerDiff($iTimerDiff)
ConsoleWrite($iString & " - " & $iTimerDiff & @LF)

$iTimerDiff = TimerInit()
$iString = StringRegExp($sFileData, "TestXXXX", 0, 2767600)
$iTimerDiff = TimerDiff($iTimerDiff)
ConsoleWrite($iString & " - " & $iTimerDiff & @LF)

2767692 - 0.00829366853445348
1 - 34.3946332855723
1 - 29.7493890330846

however looking at the speed of StringInStr, and also have this option in StringReplace\StringRegExpReplace would be really helpful

Sorry for my english

Ciao.

Attachments (0)

Change History (15)

comment:1 Changed 8 years ago by TicketCleanup

  • Version 3.3.8.1 deleted

Automatic ticket cleanup.

comment:2 Changed 8 years ago by DXRW4E

sorry, post by mistake

it seems that in StringInStr works really well and quickly, instead StringRegExp does not work well in almost as if it does not work at all

Local $sFileData, $iString, $iTimerDiff

$sFileData =  FileRead(@DesktopDir& "\test.ini") ; test.ini = 10 Mb - includes inside, the string TestXXXX

$iTimerDiff = TimerInit()
$iString = StringInStr($sFileData, "TestXXXX", 1, 1, 2767600)
$iTimerDiff = TimerDiff($iTimerDiff)
ConsoleWrite($iString & " - " & $iTimerDiff & @LF)

$iTimerDiff = TimerInit()
$iString = StringRegExp($sFileData, "TestXXXX")
$iTimerDiff = TimerDiff($iTimerDiff)
ConsoleWrite($iString & " - " & $iTimerDiff & @LF)

$iTimerDiff = TimerInit()
$iString = StringRegExp($sFileData, "TestXXXX", 0, 2767600)
$iTimerDiff = TimerDiff($iTimerDiff)
ConsoleWrite($iString & " - " & $iTimerDiff & @LF)

2767692 - 0.00829366853445348
1 - 34.3946332855723
1 - 29.7493890330846

Ciao.

comment:3 Changed 8 years ago by James

DXRW4E, are you using the latest beta? The regex compiler that AutoIt uses has been updated. Can you give that a go please?

comment:4 Changed 8 years ago by DXRW4E

Yes, I always use the latest Beta, where I noticed that StringRegExpReplace has been improved a lot about the speed in the Case-sensitivity Mod, however have a flag "Offset\The starting position of the search" in StringReplace or in StringRegExpReplace,
as in StringInStr and StringMid that working really fast, would be really helpful

Ciao.

comment:5 Changed 8 years ago by DXRW4E

Local $sFileData, $iString, $iTimerDiff

$sFileData =  FileRead(@DesktopDir& "\fff.inf") ; test.ini = 11 Mb - includes inside, the string TestXXXX

$iTimerDiff = TimerInit()
$iString = StringInStr($sFileData, "TestXXXX", 1, 1, 7188000)
$iTimerDiff = TimerDiff($iTimerDiff)
ConsoleWrite($iString & " - " & $iTimerDiff & @LF)

$iTimerDiff = TimerInit()
$iString = StringRegExp($sFileData, "TestXXXX")
$iTimerDiff = TimerDiff($iTimerDiff)
ConsoleWrite($iString & " - " & $iTimerDiff & @LF)

$iTimerDiff = TimerInit()
$iString = StringRegExp($sFileData, "TestXXXX", 0, 7188000)
$iTimerDiff = TimerDiff($iTimerDiff)
ConsoleWrite($iString & " - " & $iTimerDiff & @LF)


;~ >Running:(3.3.9.15):C:\Program Files (x86)\AutoIt3\Beta\autoit3.exe "C:\Users\DXRW4E\Desktop\New AutoIt v3 Script (Beta).au3"    
;~ --> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
;~ 7188325 - 0.0319898769811509
;~ 1 - 37.974748533896
;~ 1 - 28.9295120832874
;~ +>08:32:23 AutoIt3.exe ended.rc:0

;~ >Running:(3.3.8.1):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\DXRW4E\Desktop\New AutoIt v3 Script (Beta).au3"    
;~ --> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
;~ 7188325 - 0.0157974701141486
;~ 1 - 101.169368231525
;~ 1 - 87.8702680159286
;~ +>08:31:58 AutoIt3.exe ended.rc:0

comment:6 Changed 7 years ago by BrewManNH

  • Owner set to Jon
  • Status changed from new to assigned

comment:7 Changed 12 months ago by Jpm

analysing carefully lead me to this conclusion
as the example does not reproduce the return behavior of StringReplace
but itis true that the StringRegReplace divide bt around 10
so StringReplace internally it is good that it call StringRegReplace

the gain of introducing and offset is very limited some percent with very big string
so I propose not to add it but just implement the inernal call in StringReplace

Local $sFileData, $iString, $iTimerDiff, $iExtended
Local $sTestINI = @DesktopDir& "\test.ini"
FileDelete($sTestINI)

Local $iFactor = 1
;~ Local $iOffset = 1/$iFactor
Local $iOffset = 2767600/$iFactor

If Not FileExists($sTestINI) Then
	Local $hOut = FileOpen($sTestINI, 2)
	For $i = 1 TO 1000000/$iFactor
		FileWriteLine($hOut, "          ")
	Next
	FileFlush($hOut)
	FileSetPos($hOut, $iOffset + 1, 0)
	FileWrite($hOut, "TestXXXX")
	FileClose($hOut)
EndIf
$sFileData =  FileRead(@DesktopDir& "\test.ini") ; test.ini = 10 Mb - includes inside, the string TestXXXX

$iTimerDiff = TimerInit()
$iString = StringReplace($sFileData, "TestXXXX", "TestYYYYY", 1)
$iExtended = @extended
$iTimerDiff = TimerDiff($iTimerDiff)
ConsoleWrite( "StringReplace " & $iExtended & " - " & $iTimerDiff & ' : $iString lenght = ' & Stringlen($iString) & '    Extended code: ' & $iExtended & @LF )
$iString=0

$iTimerDiff = TimerInit()
$iString = StringRegExpReplace($sFileData, "TestXXXX", "TestYYYYY", 1)
$iExtended = @extended
$iTimerDiff = TimerDiff($iTimerDiff)
ConsoleWrite( "StringRegExpReplace " & $iExtended & " - " & $iTimerDiff & ' : $iString lenght = ' & Stringlen($iString) & '    Extended code: ' & $iExtended & @LF & @LF)
$iString=0

$iTimerDiff = TimerInit()
$iString = StringInStr($sFileData, "TestXXXX", 1, 1, $iOffset)
$iTimerDiff = TimerDiff($iTimerDiff)
ConsoleWrite("StringInStr " & $iString & " - " & $iTimerDiff & @LF & @LF)

$iTimerDiff = TimerInit()
$iString = StringRegExp($sFileData, "TestXXXX", 1)
$iTimerDiff = TimerDiff($iTimerDiff)
ConsoleWrite("StringRegExp with offset " & 1 & " - " & $iTimerDiff & @LF)

$iTimerDiff = TimerInit()
$iString = StringRegExp($sFileData, "TestXXXX", 1, $iOffset)
$iTimerDiff = TimerDiff($iTimerDiff)
ConsoleWrite( "StringRegExp with offset " & $iOffset & " - " & $iTimerDiff & @LF)

;~ ================================= usual execution ===============================================
;~ StringReplace 1 - 216.104 : $iString lenght = 12000001    Extended code: 1
;~ StringRegExpReplace 1 - 31.271 : $iString lenght = 12000001    Extended code: 1

;~ StringInStr 2767602 - 0.0032

;~ StringRegExp with offset 1 - 11.9549
;~ StringRegExp with offset 2767600 - 8.2544


;~ ================================= some unusual execution ===============================================
;~ StringReplace 1 - 239.7323 : $iString lenght = 12000001    Extended code: 1
;~ StringRegExpReplace 1 - 30.3199 : $iString lenght = 12000001    Extended code: 1

;~ StringInStr 2767602 - 0.0045

;~ StringRegExp with offset 1 - 9.4972
;~ StringRegExp with offset 2767600 - 11.3512 >>>>>>>>>>>>>>>>> usely less than with offset = 1 <<<<<<<<<<<<<<<<<<<<<

comment:8 Changed 12 months ago by Jpm

in fact the main problem comes from the case sensitivity checking
so only this will be fixed

comment:9 Changed 12 months ago by Jpm

Fix sent to Jon

comment:10 Changed 12 months ago by Jpm

  • Owner changed from Jon to Jpm

comment:11 Changed 10 months ago by Jpm

I reopen it as the proposed solution is not working when a special character is included in the replacement string \ . $ | [ ( { * + ? #
so I will just modified the StringReplace doc to point to StringRegExpReplace as the solution to use the same implementation will need to scan input string char by char as the present StringReplace implementation does.
It is better that the specific pattern of StringRegExpReplace be the user responsability.

comment:12 Changed 10 months ago by Jpm

  • Milestone set to 3.3.15.4
  • Resolution set to Completed
  • Status changed from assigned to closed

Added by revision [12451] in version: 3.3.15.4

comment:13 Changed 10 months ago by Jpm

  • Resolution Completed deleted
  • Status changed from closed to reopened

comment:14 Changed 10 months ago by Jpm

  • Status changed from reopened to assigned

Finally I get a solution.
I sent the fix to Jon

comment:15 Changed 10 months ago by TicketCleanup

  • Milestone 3.3.15.4 deleted

Automatic ticket cleanup.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as assigned The owner will remain Jpm.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.