Re: Mathematica output that slow???
- To: mathgroup at smc.vnet.net
- Subject: [mg61175] Re: [mg61138] Mathematica output that slow???
- From: "David Annetts" <davidannetts at aapt.net.au>
- Date: Wed, 12 Oct 2005 01:42:01 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Hi Kevin, > I am having trouble writing to output files from Mathematica. > Actually doing the output is trivial, but the time it takes > to complete the operation seems quite slow. Perhaps I should > describe how I use the Write[] function. Basically at the > beginning of the program I open a file to write to with > OpenWrite[]. Then my program carries out a couple hundred > calculations and writes one line to the outputstream and > repeats, a couple hundred more calcs and another one line > write. Finally, when the program is complete I Close[] the > output file. My problem is that in writing files that are > tens of thousands of lines long, the process seems quite slow > compared to its Fortran counterpart. Is there a better way > to write like this in Mathematica (by better I mean faster). :) It might be slow compared to Fortran (any breed), but Fortran also slows down considerably when it has to do IO. Try writing intermediate results (either to screen or file) and see what I mean. Have you tried saving the results you want to write to an array, then writing that array when your calculations are complete? In pseudo-code you might try output = {}; ( calcs; output = AppendTo[output, current_results]; )& /@ Range[]; Export[output]; Regards, Dave.