hugov, if you would look in the documentation, you would see that I implemented some options already, and even more than you
. Like your function, padding of line numbers to right justify them is possible. My version uses padding with spaces at default. The features of the two functions are different:Same features:
[*:3lck3cff]They two can pad line numbers, but lineNum() can use zeros or spaces only (3rd Option: format
where TF_LineNumber() can use any character for that (2nd and 4rd Options: Leading
).lineNum only features:
[*:3lck3cff]Can start the initial line number different than 1, i.e. 0 or any other positive value. (5rd Option: start
[*:3lck3cff]Separator string between the line numbers and the actual original lines can be specified other than space, i.e. double colon and space. (3rd Option: sep
[*:3lck3cff]Its possible to add line numbers to lines with printable characters only. (2rd Option: mode
)TF_LineNumber only features:
[*:3lck3cff]Line numbering can be reseted at specified interval of processed lines. (3rd Option: Restart
I wanted to know which of them operates faster. Results with benchmark settings iter=100 and high=1 on VanillaAHK: (lower is better)
0.125147 -> lineNum_settings1 (by Tuncay, default settings)
0.229914 -> TF_LineNumber_settings1 (by hugov, default settings)
0.133491 -> lineNum_settings2 (by Tuncay, mimic TFs default)
0.236031 -> TF_LineNumber_settings2 (by hugov, mimic lineNums default)
Only default settings are covered, because if someone needs a feature not present in one of the functions, the time savings are not a selection-criterion. And this is the benchmark script:
iter := 100 ; iteration, number of how many times the text should be replicated and function called
high := 1 ; false=use actual A_BatchLines and priority, true =use SetBatchLines, -1 and high priority
Following and preceding line contains 4 spaces.
This is line 8
Line 9 follows.
Following line is empty
out .= "`n" . benchmark("lineNum_settings1", "by Tuncay, default settings", text_template, iter, high)
out .= "`n" . benchmark("TF_LineNumber_settings1", "by hugov, default settings", text_template, iter, high)
out .= "`n`n" . benchmark("lineNum_settings2", "by Tuncay, mimic TFs default", text_template, iter, high)
out .= "`n" . benchmark("TF_LineNumber_settings2", "by hugov, mimic lineNums default", text_template, iter, high)
MsgBox, 1, Benchmark results, Ok copies to clipboard`n`n%out%
Clipboard := out
lineNum(_param, 1, " ", 0)
TF_LineNumber(_param, true, false, " ")
benchmark(_func, _desc="", _param="", _i=100, _high=false)
BatchLines := A_BatchLines
If (_param = "")
text .= "`n" . A_Index
VarSetCapacity(_text, StrLen(_param) * _i)
Loop, % _i - 1
text .= _param
If (_high) ; Do not change prior call of SetBatchLines, -1
Process, priority, , High
if IsFunc("benchmark_" . _func)
StartTime := isFunc("QPX") ? QPX(true) : A_TickCount
ElapsedTime := isFunc("QPX") ? QPX(false) : A_TickCount - StartTime
result := ElapsedTime . "`t -> " . _func . " (" . _desc . ")"
result := "---" . "`t -> " . _func . " <function not found>"
The benchmark script uses QPX, if it is included or in stdlib folder), otherwise simple A_TickCount is used.
Mine version is faster. And there is a lot of room for optimizations.