Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!newspump.sol.net!posts.news.twtelecom.net!nnrp3.twtelecom.net!not-for-mail From: "Kevin J. McCann" Newsgroups: comp.soft-sys.math.mathematica Subject: Re: Quantity[] (Units) slows things! Solutions? Date: Sat, 17 Aug 2013 06:04:08 +0000 (UTC) Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator Message-ID: References: Lines: 60 Organization: Time-Warner Telecom NNTP-Posting-Date: 17 Aug 2013 06:07:10 GMT NNTP-Posting-Host: 3aa799d6.news.twtelecom.net X-Trace: DXC=B0;368dDl`T144X5D4^0KSC_A=>8kQj6]MOj3YM9`=aX4d==k:3i Hi, > > This is for Mathematica9 which introduced units-handling via the Quantity[] function and its friends. It's a nice provision, but can slow things down substantially for production work, e.g. below shows a factor of 6500 slowdown! > > For example: > > lwc[dBZ_, sigma_, n_Quantity] := (1/6) Exp[-9 sigma^2/2] Pi > Quantity[1.,"Grams"/("Centimeters"^3)] > Sqrt[n (10^(dBZ/10)) > Quantity[1., ("Millimeters")^6/("Meters"^3)]] > > Timing[Table[lwc[dbz, 0.35, > Quantity[200., 1/("Centimeters"^3)]], > {dbz, -100., -10., 0.1}]] > > ===>>65 Seconds! > > whereas the unitless equivalent: > > lwcn[dBZ_, sigma_, n_] := (1/6) Exp[-9 sigma^2/2] Pi > 1.0 Sqrt[n (10^(dBZ/10)) ] > > Timing[Table[lwcn[dbz, 0.35, 200.], {dbz, -100., -10., 0.1}]] > > ===>>0.01 Seconds! > > > Can anyone suggest any tricks other than removing the units-handling? > > > >