由于思考并发提升性能的问题,想到了要测试一下读取文件有多快/慢?
下面的代码读取了一个csv文件,统计了每秒能读取读少行。结果还是不错的。
#!/usr/bin/newlisp
(setq t1 (date-value))
(set 'in-file (open "dw_product_dt.csv" "read"))
(setq counter 0)
(while (read-line in-file)
(inc counter))
(close in-file)
(setq t2 (date-value))
(setq duration (- t2 t1))
(println "totol line number: " counter)
(println (format "read %lld lines per second" (/ counter duration)))
(exit)
$ ./file-read-speed.lsp
totol line number: 122137863
read 6785436 lines per second
结果如下:
# ./file-read-speed.lsp
totol line number: 143449
read 143449 lines per second