Which patterns with what input?
This is just a simple benchmark script. I haven't fully tested with various different patterns and options.
; Sample Text
file := A_ScriptDir "\text.txt"
if !FileExist(file) {
tooltip, Creating a file...
FileDelete, % file
HayStack := "fully armed, we determined that a human form from the cross."
. " The regret landscapes route out. Spiros hears that means."
. " It flows into a moment, ultimate map of the influence of "
. "the protector, born in, for a little adobe house outside "
. "of the ancient magic. Ω He pours himself in swooning in the " ;embedded a unicode character, Ω
. "mirror, I got a random line: —See, my clodes, and throws heaps"
. " of elfin beauty, radiant, literally ælfscínu, they have set up?"
. " —**** me…the final evidence. How does the world with the flame "
. "of warning. ā —But there and cracks another 19 Audio and we do " ;embedded a unicode character, ā
. "you will they" ;generated at http://johno.jsmf.net/knowhow/ngrams/
loop 10000
FileAppend, % HayStack "`n", % file, UTF-8
}
; Variables and Objects
FileRead, HayStack, % file
oNeedles := ["\QΩ\E", "S)\QΩ\E", "\Qā\E", "S)\Qā\E"]
repeat := 1000
result .= A_AHKVersion (A_IsUnicode ? " Unicode" : " Ansi") (A_PtrSize = 8 ? " x64" : " x32") "`n`n"
; test RegexMatch
result .= "RegexMatch`n"
Loop 2 ; one is with S) and one is without it
{
Index := A_Index
tooltip, % "Benchmarking... needle: " oNeedles[Index]
StartTime := A_TickCount
occurrence := 0,
h := HayStack , n := oNeedles[Index]
loop % repeat
{
spos := 1, pos := 1
While (pos := RegexMatch(h, n, m, pos + strlen(m)))
++occurrence
}
result .= "Needle:" A_Tab oNeedles[Index] "`n"
. "Count:" A_Tab occurrence "`n"
. "Elapsed:" A_Tab (A_TickCount - StartTime) / 1000 "`n`n"
}
; test RegexReplace
result .= "RegexReplace`n"
Loop 2 ; one is with S) and one is without it
{
Index := A_Index + 2
tooltip, % "Benchmarking... needle: " oNeedles[Index]
StartTime := A_TickCount
occurrence := 0
h := HayStack, n := oNeedles[Index]
loop % repeat
RegexReplace(h, n, "", count), occurrence += count
result .= "Needle:" A_Tab oNeedles[Index] "`n"
. "Count:" A_Tab occurrence "`n"
. "Elapsed:" A_Tab (A_TickCount - StartTime) / 1000 "`n`n"
}
tooltip
clipboard := result
msgbox % result
The results (on WIndows 7 64-bit):
1.1.07.01 Unicode x32
RegexMatch
Needle: \QΩ\E
Count: 10000000
Elapsed: 556.705000
Needle: S)\QΩ\E
Count: 10000000
Elapsed: 78.313000
RegexReplace
Needle: \Qā\E
Count: 10000000
Elapsed: 193.909000
Needle: S)\Qā\E
Count: 10000000
Elapsed: 34.913000
1.1.07.01 Unicode x32 pcre830
RegexMatch
Needle: \QΩ\E
Count: 10000000
Elapsed: 31.574000
Needle: S)\QΩ\E
Count: 10000000
Elapsed: 31.824000
RegexReplace
Needle: \Qā\E
Count: 10000000
Elapsed: 17.004000
Needle: S)\Qā\E
Count: 10000000
Elapsed: 19.625000
1.1.07.01 Unicode x64 pcre830
RegexMatch
Needle: \QΩ\E
Count: 10000000
Elapsed: 31.731000
Needle: S)\QΩ\E
Count: 10000000
Elapsed: 30.326000
RegexReplace
Needle: \Qā\E
Count: 10000000
Elapsed: 16.973000
Needle: S)\Qā\E
Count: 10000000
Elapsed: 17.597000
1.1.07.01 Ansi x32 pcre830
RegexMatch
Needle: \QΩ\E
Count: 10000000
Elapsed: 26.864000
Needle: S)\QΩ\E
Count: 10000000
Elapsed: 31.387000
RegexReplace
Needle: \Q?\E
Count: 70000000
Elapsed: 23.026000
Needle: S)\Q?\E
Count: 70000000
Elapsed: 24.414000