From: Edgardo G. <edg...@cr...> - 2003-01-27 13:53:19
|
Hi Try with this import StringIO import time file = open('PrintTest.txt', 'w') item = "some, comma, separated, values\n" buff = StringIO.StringIO() t1 = time.time() # xrange for i in xrange(10000): buff.write(item) buff.seek(0) file.write(buff.read(buff.len)) buff.close() file.close() print time.time() - t1 Edgardo Genini edg...@cr... Patrick Chamberlain wrote: > Hi > > If this is not the right place to ask this question, please accept my > appolgies and kindly point me in the right direction. I've tried searching > comp.lang.python and general Googling without success. > > My question is: > > Is there a big performance problem printing to a file from Jython using the > simple print >> file, expression syntax? > Or have a made a dumb newbie blunder? > > The background is: > > I've been experimenting with using Jython to experiment with extracting > data from a number of databases and printing the results in csv format to a > file. Jython has made it very easy to quickly write something using the > Java libraries I already have access to. I was so impressed I wanted to > recommend using the Jython code itself in production, but I have hit a > problem when printing to a file from Jython. > > I'm typically printing 10,000 rows to a file, with some reformatting. > Trying to narrow the problem down, I've now eliminated everything from the > code except the printing to file part. Stripped right down the code is > trivial ... > > file = open ("PrintTest.txt",'w') > item = "some, comma, separated, values" > for i in range (10000): > print >> file, item > file.close() > > In Jython this is running painfully slowly. For example > > On Win2K/Pentium3/256MB/Java 1.4/Jython 2.1 this is taking about 5 minutes, > there's heavy hard disk activity. On the same machine the same code run > from Python 2.2 completes in under 1 sec. > > I tried the same code on Solaris 8 and got a similar dramatic difference > between Python and Jython, although a bit less of a difference than on Windows. > > Thanks in advance > > Patrick Chamberlain > > ------------------------------------------------------- > This SF.NET email is sponsored by: > SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! > http://www.vasoftware.com > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users |