Re: Nim's strutils.split() slower than Python's string split()?

2020-04-26 Thread krtekz
You are right. That's why outputs are sent to /dev/null in my tests.


Re: Nim's strutils.split() slower than Python's string split()?

2020-04-25 Thread krtekz
All my tests were done by redirecting stdout to /dev/null, so the performance 
of terminal doesn't matter.


Re: Nim's strutils.split() slower than Python's string split()?

2020-04-25 Thread krtekz
See updated code above


Re: Nim's strutils.split() slower than Python's string split()?

2020-04-25 Thread krtekz
Just found out something people haven't mentioned yet (or I missed it?). 
According to 
[https://nim-lang.org/docs/system.html](https://nim-lang.org/docs/system.html) 
`echo` is equivalent to a `writeLine` and a `flushFile`, so each time I call 
`echo` it flushes the output, which is not necessary. After I replaced `echo x` 
in my code with `writeLine(stdout, x)`, it helped quite a bit.

Using using split iterator instead of assigning split() return to a variable 
helps too. 


Re: Nim's strutils.split() slower than Python's string split()?

2020-04-24 Thread krtekz
Thanks a lot! Total newbie here


Re: Nim's strutils.split() slower than Python's string split()?

2020-04-24 Thread krtekz
With `-d:danger`, it improves a bit but still much slower than the Python 
version.

Nim: 2.65s, Python: 1.26s


Nim's strutils.split() slower than Python's string split()?

2020-04-24 Thread krtekz
My Nim code: 


import strutils

for ln in stdin.lines:
  echo ln.split('\t')[4]


Run

And the Python code: 


import sys

for ln in sys.stdin:
print(ln.split('\t')[4])


Run

Tested on a TSV file of 1M lines, the Nim version (compiled with -d:release) 
consistently uses more than twice the time required by the Python version.

Is it because of split() or something else?