Hello, Does print function make the code run slower? I'm storing the n
Hello,
Does print function make the code run slower?
I'm storing the needed results in an external text file, but I would like to know if the print function will make it run slower or not?
Thanks in advance :)
Ganesan CPosted Aug 21, 2021, 3:56 AM
Sagar LadPosted Aug 19, 2021, 2:31 PM
True.
target = open('target.txt', 'w') for item in xrange(4000000): target.write(str(item)+'\n') print item
Timing it:
[gp@imdev1 /tmp]$ time python large.py real 1m51.690s user 0m10.531s sys 0m6.129s gp@imdev1 /tmp]$ ls -lah target.txt -rw-rw-r--. 1 gp gp 30M Nov 8 16:06 target.txt
Now running the same with "print" commented out:
gp@imdev1 /tmp]$ time python large.py real 0m2.584s user 0m2.536s sys 0m0.040s
Rajanikant HawaldarPosted Mar 3, 2021, 7:29 AM
RameshPosted Mar 2, 2021, 11:40 AM
Rajanikant HawaldarPosted Mar 2, 2021, 10:08 AM
Sachin SinghPosted Mar 1, 2021, 11:49 AM