Tcl Code Refactoring, Part 2
lreplacehas to re-create another list after the replacement, it is still better than going through the whole list.
With this modification, I managed to squeeze another 0.7 second out from the run time. Ok, I think I am kind of hitting the performance limit, so what will be the next step. Since I am learning Python, may be the snake has something to offer.
#! /usr/bin/python import csv, sys if len(sys.argv) != 3: print "Usage:", sys.argv, "csv(in) csv(out)" exit(1) reader=csv.reader(open(sys.argv,"r")) writer=csv.writer(open(sys.argv,"w")) for row in reader: writer.writerow(row)
Comparing the above functionality with Tcl, Python is 6 times faster! With the characteristics of list object in Python being mutable, it is very efficient to replace values in Python list. However, in Tcl you will have to recreate another list object.
For this exercise, I will definitely go the Python way. So stay tune for more performance news. To be continued ...