我正在比较读取包含文件的行数的性能。
我首先使用 wc 命令行工具完成了它:
$ time wc -l bigFile.csv
1673820 bigFile.csv
real 0m0.157s
user 0m0.124s
sys 0m0.062s
然后在一个干净的 Pharo Core Smalltalk 最新的 1.3
| file lineCount |
Smalltalk garbageCollect.
( Duration milliSeconds: [ file := FileStream readOnlyFileNamed: 'bigFile.csv'.
lineCount := 0.
[ file atEnd ] whileFalse: [
file nextLine.
lineCount := lineCount + 1 ].
file close.
lineCount. ] timeToRun ) asSeconds.
15
如何加快 Smalltalk 代码的速度,使其比 wc 性能更快或更接近?