Performance Applescript慢得令人痛苦

Performance Applescript慢得令人痛苦,performance,applescript,Performance,Applescript,我是applescript新手,不知道您是否看到我的以下代码有问题,因为它速度非常慢: set myPath to ((path to desktop as text) & "a.txt") as alias set myFile to read myPath set myText to paragraphs of myFile set rowCounter to 0 repeat with nextline in myText set rowCounter to rowCou

我是applescript新手,不知道您是否看到我的以下代码有问题,因为它速度非常慢:

set myPath to ((path to desktop as text) & "a.txt") as alias
set myFile to read myPath
set myText to paragraphs of myFile
set rowCounter to 0

repeat with nextline in myText
    set rowCounter to rowCounter + 1
end repeat

rowCounter
我打开的文本文件很大(约110万条记录)。VBA中的相同代码打开它并在大约7秒钟内计算行数,而使用applescript则花费了10分钟的大部分时间

我做错什么了吗

谢谢,
Alex

像您这样的重复循环很可能要花很长时间才能处理 并且不必只使用重复循环来计算列表中的项目

您已经有了所有段落的项目列表

因此,您应该能够只列表中的项目数

Set rowcounter to number of items in myText

也作为旁白

重复循环未使用索引变量“nextline”

如果您想迭代每个项目,可以使用以下内容:

Repeat with nextline from 1 to count of myText

Set thisItem to nextline of myText


....

您也可以尝试以下方法:

set myPath to POSIX path of ((path to desktop as text) & "a.txt")
set lineCount to (do shell script "wc -l " & quoted form of myPath & " | sed -E 's/^ *([[:digit:]]+).*/\\1/'") as number
set myPath to POSIX path of ((path to desktop as text) & "a.txt")
set lineCount to (do shell script "wc -l " & quoted form of myPath & " | sed -E 's/^ *([[:digit:]]+).*/\\1/'") as number