RE: How to write fast into a file in python?

2013-05-20 Thread Carlos Nepomuceno
Oh well! Just got a flashback from the old times at the 8-bit assembly line. Dirty deeds done dirt cheap! lol Date: Sun, 19 May 2013 16:44:55 +0100 From: pyt...@mrabarnett.plus.com To: python-list@python.org Subject: Re: How to write fast into a file

Re: How to write fast into a file in python?

2013-05-19 Thread Chris Angelico
On Sun, May 19, 2013 at 3:31 PM, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: Thanks Dan! I've never used CPython or PyPy. Will try them later. CPython is the classic interpreter, written in C. It's the one you'll get from the obvious download links on python.org. ChrisA --

RE: How to write fast into a file in python?

2013-05-19 Thread Carlos Nepomuceno
ooops! I meant to say Cython. nevermind... Date: Sun, 19 May 2013 19:21:54 +1000 Subject: Re: How to write fast into a file in python? From: ros...@gmail.com To: python-list@python.org On Sun, May 19, 2013 at 3:31 PM, Carlos Nepomuceno

Re: How to write fast into a file in python?

2013-05-19 Thread MRAB
On 19/05/2013 04:53, Carlos Nepomuceno wrote: Date: Sat, 18 May 2013 22:41:32 -0400 From: da...@davea.name To: python-list@python.org Subject: Re: How to write fast into a file in python? On 05/18/2013 01:00 PM, Carlos Nepomuceno wrote: Python really

Re: How to write fast into a file in python?

2013-05-19 Thread Tim Roberts
Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: Python really writes '\n\r' on Windows. Just check the files. It actually writes \r\n, but it's not Python that's doing it. It's the C runtime library. And, of course, you can eliminate all of that by opening the file in binary mode

RE: How to write fast into a file in python?

2013-05-18 Thread Fábio Santos
On 17 May 2013 19:38, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: Think the following update will make the code more portable: x += len(line)+len(os.linesep)-1 Not sure if it's the fastest way to achieve that. :/ Putting len(os.linesep)'s value into a local variable will make

Re: How to write fast into a file in python?

2013-05-18 Thread 88888 Dihedral
Steven D'Aprano於 2013年5月18日星期六UTC+8下午12時01分13秒寫道: On Fri, 17 May 2013 21:18:15 +0300, Carlos Nepomuceno wrote: I thought there would be a call to format method by '%d\n' % i. It seems the % operator is a lot faster than format. I just stopped using it because I read it was going

Re: How to write fast into a file in python?

2013-05-18 Thread Chris Angelico
On Sat, May 18, 2013 at 5:49 PM, Fábio Santos fabiosantos...@gmail.com wrote: Putting len(os.linesep)'s value into a local variable will make accessing it quite a bit faster. But why would you want to do that? You mentioned \n translating to two lines, but this won't happen. Windows will not

RE: How to write fast into a file in python?

2013-05-18 Thread Carlos Nepomuceno
Python really writes '\n\r' on Windows. Just check the files. Internal representations only keep '\n' for simplicity, but if you wanna keep track of the file length you have to take that into account. ;) Date: Sat, 18 May 2013 08:49:55 +0100 Subject: RE: How

Re: How to write fast into a file in python?

2013-05-18 Thread Dan Stromberg
With CPython 2.7.3: ./t time taken to write a file of size 52428800 is 15.86 seconds time taken to write a file of size 52428800 is 7.91 seconds time taken to write a file of size 52428800 is 9.64 seconds With pypy-1.9: ./t time taken to write a file of size 52428800 is 3.708232

Re: How to write fast into a file in python?

2013-05-18 Thread Roy Smith
In article mailman.1813.1368904489.3114.python-l...@python.org, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: tOn Sat, 18 May 2013 08:49:55 +0100, Fábio Santos fabiosantos...@gmail.com declaimed the following in gmane.comp.python.general: You mentioned \n translating to two lines, but

Re: How to write fast into a file in python?

2013-05-18 Thread Fábio Santos
On 18 May 2013 20:19, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: tOn Sat, 18 May 2013 08:49:55 +0100, Fábio Santos fabiosantos...@gmail.com declaimed the following in gmane.comp.python.general: You mentioned \n translating to two lines, but this won't happen. Windows will not mess

Re: How to write fast into a file in python?

2013-05-18 Thread Steven D'Aprano
On Sat, 18 May 2013 15:14:31 -0400, Dennis Lee Bieber wrote: tOn Sat, 18 May 2013 08:49:55 +0100, Fábio Santos fabiosantos...@gmail.com declaimed the following in gmane.comp.python.general: You mentioned \n translating to two lines, but this won't happen. Windows will not mess with what

Re: How to write fast into a file in python?

2013-05-18 Thread Dave Angel
On 05/18/2013 01:00 PM, Carlos Nepomuceno wrote: Python really writes '\n\r' on Windows. Just check the files. That's backwards. '\r\n' on Windows, IF you omit the b in the mode when creating the file. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list

RE: How to write fast into a file in python?

2013-05-18 Thread Carlos Nepomuceno
Date: Sat, 18 May 2013 22:41:32 -0400 From: da...@davea.name To: python-list@python.org Subject: Re: How to write fast into a file in python? On 05/18/2013 01:00 PM, Carlos Nepomuceno wrote: Python really writes '\n\r' on Windows. Just check the

RE: How to write fast into a file in python?

2013-05-18 Thread Carlos Nepomuceno
Thanks Dan! I've never used CPython or PyPy. Will try them later. I think the main difference between your create_file_numbers_file_like() and the fastwrite5.py I sent earlier is that I've used cStringIO instead of StringIO. It took 12s less using cStringIO. My numbers are much greater, but

RE: How to write fast into a file in python?

2013-05-18 Thread Carlos Nepomuceno
BTW, I've downloaded from the following places: http://stromberg.dnsalias.org/svn/bufsock/trunk/bufsock.py http://stromberg.dnsalias.org/~dstromberg/backshift/documentation/html/python2x3-pysrc.html Are those the latest versions? From:

Re: How to write fast into a file in python?

2013-05-17 Thread Dave Angel
On 05/17/2013 12:35 AM, lokeshkopp...@gmail.com wrote: On Friday, May 17, 2013 8:50:26 AM UTC+5:30, lokesh...@gmail.com wrote: I need to write numbers into a file upto 50mb and it should be fast can any one help me how to do that? i had written the following code.. SNIP value = 0 with

RE: How to write fast into a file in python?

2013-05-17 Thread Carlos Nepomuceno
I've got the following results on my desktop PC (Win7/Python2.7.5): C:\src\Pythonpython -m timeit -cvn3 -r3 execfile('fastwrite2.py') raw times: 123 126 125 3 loops, best of 3: 41 sec per loop C:\src\Pythonpython -m timeit -cvn3 -r3 execfile('fastwrite5.py') raw times: 34 34.3 34 3 loops, best

Re: How to write fast into a file in python?

2013-05-17 Thread Steven D'Aprano
On Fri, 17 May 2013 18:20:33 +0300, Carlos Nepomuceno wrote: I've got the following results on my desktop PC (Win7/Python2.7.5): C:\src\Pythonpython -m timeit -cvn3 -r3 execfile('fastwrite2.py') raw times: 123 126 125 3 loops, best of 3: 41 sec per loop Your times here are increased

RE: How to write fast into a file in python?

2013-05-17 Thread Carlos Nepomuceno
Thank you Steve! You are totally right! It takes about 0.2s for the f.write() to return. Certainly because it writes to the system file cache (~250MB/s). Using a little bit different approach I've got: C:\src\Pythonpython -m timeit -cvn3 -r3 -sfrom fastwrite5r import run run() raw times: 24

Re: How to write fast into a file in python?

2013-05-17 Thread Steven D'Aprano
On Fri, 17 May 2013 18:20:33 +0300, Carlos Nepomuceno wrote: ### fastwrite5.py ### import cStringIO size = 50*1024*1024 value = 0 filename = 'fastwrite5.dat' x = 0 b = cStringIO.StringIO() while x size:     line = '{0}\n'.format(value)     b.write(line)     value += 1     x +=

RE: How to write fast into a file in python?

2013-05-17 Thread Carlos Nepomuceno
You've hit the bullseye! ;) Thanks a lot!!! Oh, I forgot to mention: you have a bug in this function. You're already including the newline in the len(line), so there is no need to add one. The result is that you only generate 44MB instead of 50MB. That's because I'm running on Windows.

RE: How to write fast into a file in python?

2013-05-17 Thread Carlos Nepomuceno
Think the following update will make the code more portable: x += len(line)+len(os.linesep)-1 Not sure if it's the fastest way to achieve that. :/ On Fri, 17 May 2013 18:20:33 +0300, Carlos Nepomuceno wrote: ### fastwrite5.py ### import cStringIO size = 50*1024*1024 value = 0 filename =

Re: How to write fast into a file in python?

2013-05-17 Thread Steven D'Aprano
On Fri, 17 May 2013 21:18:15 +0300, Carlos Nepomuceno wrote: I thought there would be a call to format method by '%d\n' % i. It seems the % operator is a lot faster than format. I just stopped using it because I read it was going to be deprecated. :( Why replace such a great and fast operator

Re: How to write fast into a file in python?

2013-05-17 Thread Chris Angelico
On Sat, May 18, 2013 at 2:01 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Consider if x is an arbitrary object, and you call %s % x: py %s % 23 # works '23' py %s % [23, 42] # works '[23, 42]' and so on for *almost* any object. But if x is a tuple, strange things

How to write fast into a file in python?

2013-05-16 Thread lokeshkoppaka
I need to write numbers into a file upto 50mb and it should be fast can any one help me how to do that? i had written the following code.. --- def create_file_numbers_old(filename, size):

Re: How to write fast into a file in python?

2013-05-16 Thread Steven D'Aprano
On Thu, 16 May 2013 20:20:26 -0700, lokeshkoppaka wrote: I need to write numbers into a file upto 50mb and it should be fast can any one help me how to do that? i had written the following code.. -- def

Re: How to write fast into a file in python?

2013-05-16 Thread lokeshkoppaka
On Friday, May 17, 2013 8:50:26 AM UTC+5:30, lokesh...@gmail.com wrote: I need to write numbers into a file upto 50mb and it should be fast can any one help me how to do that? i had written the following code..