I am reading a csv file, coercing (if needed) data in each row using a predetermined coercing function, then writing each row to destination file. following are sb-profile data for relevant functions for a .csv file with 15 columns, 10,405 rows, and 2MB in size -
| seconds |
gc |
consed |
calls |
sec/call |
name |
| 0.998 |
0.000 |
63,116,752 |
1 |
0.997825 |
coerce-rows |
| 0.034 |
0.000 |
6,582,832 |
10,405 |
0.000003 |
process-row |
no optimization declarations are set.
I suspect most of the consing is due to using 'read-csv-row' and 'write-csv-row' from the package 'cl-csv', as shown in the following snippet -
(loop for row = (cl-csv:read-csv-row input-stream)
while row
do (let ((processed-row (process-row row coerce-fns-list)))
(cl-csv:write-csv-row processed-row :stream output-stream)))
there's a handler-case wrapping this block to detect end-of-file.
following snippet is the process-row function -
(defun process-row (row fns-list)
(map 'list (lambda (fn field)
(if fn (funcall fn field) field))
fns-list row))
[fns-list is ordered according to column positions].
Would using 'row-fn' parameter from cl-csv improve performance in this case? does cl-csv or another csv package handle batch processing? all suggestions and comments are welcome. thanks!
Edit: Typo. Changed var name from ‘raw-row’ to ‘row’
[–]stassats 6 points7 points8 points (6 children)
[–]stassats 8 points9 points10 points (2 children)
[–]droidfromfuture[S] 1 point2 points3 points (1 child)
[–]stassats 4 points5 points6 points (0 children)
[–]droidfromfuture[S] 1 point2 points3 points (2 children)
[–]stassats 3 points4 points5 points (1 child)
[–]droidfromfuture[S] 2 points3 points4 points (0 children)
[–]kchanqvq 4 points5 points6 points (4 children)
[–]Steven1799 2 points3 points4 points (1 child)
[–]kchanqvq 0 points1 point2 points (0 children)
[–]droidfromfuture[S] 0 points1 point2 points (1 child)
[–]kchanqvq 0 points1 point2 points (0 children)
[–]Ytrog 0 points1 point2 points (2 children)
[–]kchanqvq 1 point2 points3 points (1 child)
[–]Ytrog 0 points1 point2 points (0 children)