MathGroup Archive 2013

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

Search the Archive

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?






  • Prev by Date: Re: Trig identity for linear combination of sines
  • Next by Date: How to remove external parentheses from a list
  • Previous by thread: Application of decision trees to waveform recognition and GDP per
  • Next by thread: Re: Quantity[] (Units) slows things! Solutions?