Drexel dragonThe Math ForumDonate to the Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Quantity[] (Units) slows things! Solutions?
Replies: 1   Last Post: Aug 17, 2013 2:04 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Kevin J. McCann

Posts: 147
Registered: 12/7/04
Re: Quantity[] (Units) slows things! Solutions?
Posted: Aug 17, 2013 2:04 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I find the new way Mathematica deals with units and physical constants to be a
rather poor change to the old Units and PhysicalConstants packages. In
addition to the fact that asking for something like the speed of light
requires an internet connection, there is the slowdown in just the
handling of units as you found.

I used the old units package, which has its own problems, to rewrite:

<< Units`

lwc2[dBZ_, sigma_, n_] :=


lwc2[dbz, 0.35, 200./(Centimeter^3)], {dbz, -100., -10., 0.1}]]

Takes about 0.5s as opposed to 23.5s on my computer.


On 8/16/2013 3:07 AM, Frank Iannarilli wrote:
> 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?

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum 1994-2015. All Rights Reserved.