MathGroup Archive 1995

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

Search the Archive

Re: Challenge! ....RESULTS...

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg1128] Re: Challenge! ....RESULTS...
  • From: roth at sunny.mpimf-heidelberg.mpg.de (Arnd Roth)
  • Date: Wed, 17 May 1995 02:09:12 -0400
  • Organization: Max-Planck-Institut fuer Medizinische Forschung

In article <3olujj$ql4 at news0.cybernetics.net>
jorma.virtamo at vtt.fi (Jorma Virtamo) writes:

> roth at sunny.mpimf-heidelberg.mpg.de. (Arnd Roth) wrote:
> 
> >...
> 
> >Villegas' function 3    villegas at wri.com
> >In[17]:=
> >swap[list1_List, list2_List] := Thread @
> >Unevaluated[If[Random[Integer] == 0, #1, #2]& [list1, list2]]
> >In[18]:= Timing[Do[swap[l1,l2],{1000}]]
> >Out[18]= {1.44 Second, Null}
> >
> >So Robby Villegas' function 3 is fastest among the solutions I
> >tested. But of course there may still be room for further
> >speedup.
> 
> Indeed, by writing the argument lists directly into the If function,
> 
>    swap[list1_List, list2_List] := Thread @
>    Unevaluated[If[Random[Integer] == 0, list1, list2]]
> 
> the execution speeds up in my Pentium to 1.483 Second 
> in contrast to 2.471 Second with the original form.
> 
> -- Jorma Virtamo

Here is a solution which is still faster:

silia% math
Mathematica 2.2 for Solaris
Copyright 1988-94 Wolfram Research, Inc.
License valid through 30 Jun 1995.
 -- Open Look graphics initialized -- 

In[1]:= l1 = {a,b,c,d,e,f,g,h,i,j};

In[2]:= l2 = {A,B,C,D,E,F,G,H,I,J};

Jorma Virtamo's function    jorma.virtamo at vtt.fi
In[3]:= swap[list1_List, list2_List] := Thread @
        Unevaluated[If[Random[Integer] == 0, list1, list2]]

In[4]:= Timing[Do[swap[l1,l2],{1000}]]

Out[4]= {1.09 Second, Null}

In[5]:= SetAttributes[Thread, HoldFirst]

In[6]:= swap[list1_List, list2_List] :=
        Thread[If[EvenQ[Random[Integer]], list1, list2]]

In[7]:= Timing[Do[swap[l1,l2],{1000}]]

Out[7]= {1.01 Second, Null}

In[8]:= Exit[]
silia%

Arnd Roth
Abteilung Zellphysiologie
Max-Planck-Institut fuer Medizinische Forschung
Postfach 10 38 20, D-69028 Heidelberg, Germany
http://sunny.mpimf-heidelberg.mpg.de/people/roth/ArndRoth.html


  • Prev by Date: Re: Find the center!
  • Next by Date: Re: Find the center!
  • Previous by thread: Re: Challenge! ....RESULTS...
  • Next by thread: What's this Mathematica function called?