Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

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: [mg57578] Re: [mg57533] reducing the time of constructing a List
  • From: János <janos.lobb at yale.edu>
  • Date: Wed, 1 Jun 2005 06:03:06 -0400 (EDT)
  • References: <200505310900.FAA03434@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On May 31, 2005, at 5:00 AM, marloo3 at mail15.com wrote:

> 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
>

1.2Ghz G4 2GB RAM OSX 10.4.1 Mathematica 5.1

In[69]:=
Timing[First[Last[
      Reap[i = 0; lengthdat =
         Length[dat];
        While[i++ < lengthdat,
         If[dat[[i]] == 1,
          Sow[{1}], Sow[
           {0}]]]]]]; ]
Out[69]=
{1.2697460000000014*Second,
   Null}


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