As a new user, I'd love to know about I/O optimization techniques for Nim.

Hence, I have this simple function for 
[https://www.fluentcpp.com/2017/09/25/expressive-cpp17-coding-challenge/](https://www.fluentcpp.com/2017/09/25/expressive-cpp17-coding-challenge/).
    
    
    import os, strutils
    
    proc main() =
      var
        pageSize: int = 4096
        input = open(paramStr(1), fmRead, pageSize)
        output = open(paramStr(4), fmWrite, pageSize)
        changeAt = 0
      
      let
        toChange = $paramStr 2
        changeWith = $paramStr 3
      
      var i: int = 0
      for column in input.readLine().split(','):
        if column == toChange:
            changeAt = i
        inc i
      
      let columns = i
      
      for row in input.lines():
        i = 0
        for entry in row.split(','):
            if i != changeAt:
                output.write entry
            else:
              output.write changeWith
            if i + 1 != columns:
                output.write(',')
            inc i
        output.writeLine("")
    
    main()
    

While the program is not expressive, I intend to use this to explore the 
possible optimizations in I/O. My question why changing pageSize does not have 
any apparent effect on the program? And how can I find an optimal pageSize for 
the system? Also, any other tips would be appreciated.

As a side note, the following (somewhat similar) python program is actually 
faster than the Nim program above:
    
    
    import sys
    
    with open(sys.argv[1]) as fin:
      head = fin.readline()
      col = head.split(',').index(sys.argv[2])
      with open(sys.argv[4], 'w') as fout:
        fout.write(head)
        for i in (x.split(',') for x in fin.readlines()):
          i[col] = sys.argv[3]
          fout.write(','.join(i))

Reply via email to