MathGroup Archive 2005

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

Search the Archive

Re: reducing the time of constructing a List

  • To: mathgroup at smc.vnet.net
  • Subject: [mg57553] Re: [mg57533] reducing the time of constructing a List
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Wed, 1 Jun 2005 06:01:38 -0400 (EDT)
  • Reply-to: hanlonr at cox.net
  • Sender: owner-wri-mathgroup at wolfram.com

n=20000;
dat=Table[Random[Integer,{0,10}],{n}];

lst={};Timing[For[i=1,i?n,If[dat[[i]]==1,lst=
      Join[lst,{1}],lst=Join[lst,{0}]];i++];]

{12.03 Second,Null}

Timing[dat/._?(#!=1&):>0;]

{0.1 Second,Null}


Bob Hanlon

> 
> From: marloo3 at mail15.com
To: mathgroup at smc.vnet.net
> Date: 2005/05/31 Tue AM 05:00:08 EDT
> Subject: [mg57553] [mg57533] reducing the time of constructing a List
> 
> please, what is the best way to reduce the timing of the following lines, the 
> source of data is:
> dat = Table[Random[Integer, {0, 10}], {100000}];
> and the purpose is to construct the List lst in the following way:
> For[i = 1, i <= 100000,
>       If [dat[[i]] == 1,
>         lst = Join[lst, {1}], lst = Join[lst, {0}]]; i++]; // Timing
> 
> Out[]= {226.07 Second, Null}
> on the P4 celeron 2 Ghz , memory 382 MB ram
> thanks
> 
> 


  • Prev by Date: Re: What is causing this error message?
  • Next by Date: Re: List searching
  • Previous by thread: Re: reducing the time of constructing a List
  • Next by thread: Re: reducing the time of constructing a List