       Extract is slow in Mathematica 4 on PPC

• To: mathgroup at smc.vnet.net
• Subject: [mg18455] Extract is slow in Mathematica 4 on PPC
• From: "William B. Marks" <bmarks at helix.nih.gov>
• Date: Wed, 7 Jul 1999 00:11:37 -0400
• Sender: owner-wri-mathgroup at wolfram.com

```Let us compare Extract to a simple less versitile alternative:
extrct[expr_, {prts__}] := expr[[ prts]].

Make arrays with 1, 2 and 3 numbers per element:
{nx, ny} = {40, 50};
arry1 = Array[#1 #2 &, {nx, ny}];
arry2 = Array[{#1, #2} &, {nx, ny}];
arry3 = Array[{#1, #2, #1 #2} &, {nx, ny}];

Make a list of parts to extract
numPrts = 1000;
prts = Array[{Random[Integer, {1, nx}], Random[Integer, {1, ny}]} &, numPrts];

Time Extract and extrct while they get the parts.
Extract[arry1, #] & /@ prts; // Timing
Extract[arry2, #] & /@ prts; // Timing
Extract[arry3, #] & /@ prts; // Timing
{1.61667 Second, Null}
{4.46667 Second, Null}
{6.9 Second, Null}

extrct[arry1, #] & /@ prts; // Timing
extrct[arry2, #] & /@ prts; // Timing
extrct[arry3, #] & /@ prts; // Timing
{0.05 Second, Null}
{0.0666667 Second, Null}
{0.0666667 Second, Null}

on a Mac PPC.

In Mathematica 3 each of these 6 calculations took .0166 Seconds,  1/4 of .06666.

The big jump in time for arrays of 2 numbers is the killer.  The jump is
greater when Extract is used within Fold instead of Map as above. Till I
understand this I will use extrct.

Cheers,
Bill Marks

```

• Prev by Date: Re: [Q] 2D graphic routines and data sets in 2D lists
• Next by Date: combining a ParametricPlot3D with a ContourPlot.
• Previous by thread: Re: [Q] 2D graphic routines and data sets in 2D lists
• Next by thread: combining a ParametricPlot3D with a ContourPlot.