Quantity[] (Units) slows things! Solutions?
- To: mathgroup at smc.vnet.net
- Subject: [mg131510] Quantity[] (Units) slows things! Solutions?
- From: Frank Iannarilli <frankeye at cox.net>
- Date: Fri, 16 Aug 2013 07:05:59 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-outx@smc.vnet.net
- Delivered-to: mathgroup-newsendx@smc.vnet.net
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?