Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*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 2000

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

Search the Archive

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


  • Prev by Date: Re: pass to a C program
  • Next by Date: Meijer G Function
  • Previous by thread: Re: File save locations - Mac
  • Next by thread: RE: Cases, Throw, and Catch