Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re:Speed of writing in Mathematica 3.01

>Date: Wed, 1 Apr 1998 21:49:44 +0900
>From: Andrzej Kozlowski <>
>Subject: [mg11884] Re:Speed of writing in Mathematica 3.01
>In article <6fd5ag$>, (James Bridges) wrote:
>> Am I doing something wrong or is it supposed to take orders of magnitude
>> longer than is reasonable to write out a simple ASCII file from
>> Mathematica? Consider this simple test:
>> In[7]:=
>> a=Table [i,{i,1,1001}];
>> In[8]:=
>> Timing[
>> filename="Macintosh HD:test.ascii";
>> output=OpenWrite[filename];
>> Do[
>>       Write[output,a[[i]]];
>> ,{i,1,1001}];
>> Close[output];
>>    ]
>> Out[8]=
>> {23.4 Second,Null}
>> 23 seconds to write 1001 integers?!  On a 233MHz G3! Everything else is
>> whiff-bam fast, but writing is glacial. Now this is a simplified
>> example of what I need to do but it contains one of the factors, namely
>> that I have to individually write out elements of a list, hence the Do
>> loop. Any hints?
>> > James Bridges
>Here is one fast way do this sort of thing:
>{0.0833333 Second,Null}
>(PowerMac G3 266 MHz)
>Andrzej Kozlowski

The example of fast Write which I sent earlier writes to file in a form
suitable for input into Mathematica. In other words you get a list
{1,2,3,...}. Actually, however your problem was that you wrapped
"Timing" around the entire composite expression, so you were not really
timing "Write" at all. If you only time "Write" you get a much faster

In[28]:= one=OpenWrite["test"]
Out[28]= OutputStream["test",11]
In[29]:= t=Table[i,{i,1,1001}];
In[30]:= Do[Write[one,t[[i]]],{i,1,1001}]//Timing Out[30]= {0.166667
In[31]:= Close[one]
Out[31]= "test"

You can still make it somewhat faster by not breaking up the list

In[32]:= two=OpenWrite["test2"]
Out[32]= OutputStream["test2",12]
In[33]:= Write[two,TableForm[Table[i,{i,1,1001}]]//OutputForm]//Timing
Out[33]= {0.116667 Second,Null}
In[34]:= Close[two]
Out[34]= "test2"

Andrzej Kozlowski

(All on G3 266 MHZ)

  • Prev by Date: Re: bivariate normal with 3dplot
  • Next by Date: Q: Loading bmp file
  • Prev by thread: Re:Speed of writing in Mathematica 3.01
  • Next by thread: Re: Speed of writing in Mathematica 3.01