Cases, Throw, and Catch
- To: mathgroup at smc.vnet.net
- Subject: [mg24182] Cases, Throw, and Catch
- From: Mark Fisher <me.fisher at atl.frb.org>
- Date: Wed, 28 Jun 2000 22:51:02 -0400 (EDT)
- Organization: Federal Reserve Bank of Atlanta
- Sender: owner-wri-mathgroup at wolfram.com
I just noticed that it is much faster to Throw and Catch from Cases than
to have Cases return the first match on its own. Does anyone know why
this is so and what, if anything, is to be learned?
Here is the example:
In[1]:=
xtab = Table[x, {10^6}];
In[2]:=
Cases[xtab, x, Infinity, 1] // Timing
Out[2]=
{0.172 Second, {x}}
In[3]:=
Catch @ Cases[xtab, Throw[{x}], Infinity, 1] // Timing
Out[3]=
{0. Second, {x}}
In[4]:=
ytab = Append[xtab, y];
In[5]:=
Cases[ytab, y, Infinity, 1] // Timing
Out[5]=
{0.437 Second, {y}}
In[6]:=
Catch @ Cases[ytab, Throw[{y}], Infinity, 1] // Timing
Out[6]=
{0. Second, {y}}
--Mark.
Mark Fisher
Economic Advisor
Research Department
Federal Reserve Bank of Atlanta
Atlanta, GA 30303
404-521-8757 (voice)
404-521-8810 (fax)
mark.fisher at atl.frb.org
personal web page: www.markfisher.net