       Why overloaded arithmetic operations are so slow?

• To: mathgroup at smc.vnet.net
• Subject: [mg49729] Why overloaded arithmetic operations are so slow?
• From: Sergey Afonin <serg at msu.ru>
• Date: Thu, 29 Jul 2004 07:45:32 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```Hi all.

standard arithmetic operations, such as Plus, for user-defined data is
"much more convenient" than defining specific functions. But how this
can be done efficiently? I want to define type of the form zz[Number]

zz /: Plus[z1_zz, z2_zz] := zz[First[z1] + First[z2]]

In fact, zz are "normal" numbers. The following statement prints out
the time spent for addition wrt the number of elements...

Do[Print[Timing[Plus @@ Table[zz[10^(i - 1)], {i, n}]]], {n, 15}]

{0. Second, zz}
{0. Second, zz}
{0. Second, zz}
{0. Second, zz}
{0. Second, zz}
{0. Second, zz}
{0. Second, zz}
{0.02 Second, zz}
{0.03 Second, zz}
{0.12 Second, zz}
{0.35 Second, zz}
{1.07 Second, zz}
{3.31 Second, zz}
{10.07 Second, zz}
{30.81 Second, zz}

Is it normal?

Best regards,
Sergey Afonin

```

• Prev by Date: PutAppend Command and Data Output
• Next by Date: RE: Combinations
• Previous by thread: Re: PutAppend Command and Data Output
• Next by thread: Re: Why overloaded arithmetic operations are so slow?