Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #10927
| From | Bill Rowe <readnews@sbcglobal.net> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Algorithm Analysis Course: Should I use Mathematica for projects? |
| Date | 2012-07-14 05:35 +0000 |
| Message-ID | <jtr0eg$bek$1@smc.vnet.net> (permalink) |
| Organization | Time-Warner Telecom |
On 7/13/12 at 2:55 AM, fateman@cs.berkeley.edu (Richard Fateman)
wrote:
>An example.
>Create 3 arrays.
>A=Table[i,{i,0,100}];
>B=Table[i,{i,0,1000}];
>Q=Table[i,{i,0,10000}];
>Try updating the 50th element of each of these items, which look
>like arrays in Mathematica.
>Timing [A[[50]],{i,0,100000}]
It is hard to understand what you mean here. If I paste what you
posted into Mathematica I see the portion {i,0,100000} colored
red. Not surprising since Timing accepts one argument not two.
Perhaps you meant something like
Timing[Do[a[[50]], {i, 100000}]]
>Timing [B[[50]],{i,0,100000}]
>Timing [Q[[50]],{i,0,100000}]
>On my computer, these results take 0.266 seconds, 0.453 seconds, and
>2.25 seconds,
Assuming you did mean repeatedly reading the 50th element of
each list, I cannot reproduce your results. I get
In[1]:= a = Range[100];
b = Range[1000];
c = Range[10000];
In[4]:= Timing[Do[a[[50]], {i, 100000}]]
Out[4]= {0.054508,Null}
In[5]:= Timing[Do[b[[50]], {i, 100000}]]
Out[5]= {0.055219,Null}
In[6]:= Timing[Do[c[[50]], {i, 100000}]]
Out[6]= {0.053313,Null}
which indicates a constant access time.
>Now, instead of creating these guys as what appears to be arrays,
>one uses
>A=Array[#&,100]
>B=Array[#&,1000]
>Q=Array[#&,10000]
>How does that change the results?
On my machine, not much
In[8]:= a = Array[# &, 100];
b = Array[# &, 1000];
c = Array[# &, 10000];
In[11]:= Timing[Do[a[50], {i, 100000}]]
Out[11]= {0.034209,Null}
In[12]:= Timing[Do[b[50], {i, 100000}]]
Out[12]= {0.032917,Null}
In[13]:= Timing[Do[c[50], {i, 100000}]]
Out[13]= {0.033273,Null}
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Algorithm Analysis Course: Should I use Mathematica for projects? Bill Rowe <readnews@sbcglobal.net> - 2012-07-14 05:35 +0000
csiph-web