Re: Re: Re: Slowdown

```I can't see any siginificant slowdowns demonstrated by your code. The
differences in timings between different combinations seem
insignificant. Cna you suggest any other name but "weirdness" that
shows significant slowdown?

Besides, using Module only obsures what is really happening. Module
simply renames local variables by appending \$somenumber to their name
but the "number" that is used is different each time. You can do that
whiteout Module and see exactly which names produce the slowdown
effect. It seems that the names weirdness\$1 to weirdness\$9 do not.

In[1]:=
L=weirdness\$1[];
Do[L=weirdness\$1[L,i],{i,10^4}]//Timing

Out[2]=
{0.03 Second,Null}

In[3]:=
L=weirdness\$9[];
Do[L=weirdness\$9[L,i],{i,10^4}]//Timing

Out[4]=
{0.08 Second,Null}

The problem seems to begin with weirdness\$10

In[5]:=
L=weirdness\$10[];
Do[L=weirdness\$10[L,i],{i,10^4}]//Timing

Out[6]=
{13.2 Second,Null}

and continues for higher values, as far as I have checked.

When you run Module with a fresh Kernel Mathematica seems to always
begin by appending \$17:

In[1]:=
Module[{weirdness, L},
L = weirdness[];
Do[L = weirdness[L, i], {i, 1}]
] // Trace

Out[1]=
{Module[{weirdness,L},L=weirdness[];Do[L=weirdness[L,i],{i,1}]],{L\$17=\
weirdness\$17[];Do[L\$17=weirdness\$17[L\$17,

i],{i,1}],{L\$17=weirdness\$17[],weirdness\$17[]},{Do[L\$17=weirdness\$17[L\$\
17,i],{i,1}],{{{L\$17,weirdness\$17[]},{i,1},weirdness\$17[weirdness\$17[],

1]},L\$17=weirdness\$17[weirdness\$17[],1],weirdness\$17[weirdness\$17[],1]\
},Null},Null},Null}

on subsequent runs this is increased:

In[2]:=
Module[{weirdness, L},
L = weirdness[];
Do[L = weirdness[L, i], {i, 1}]
] // Trace

Out[2]=
{Module[{weirdness,L},L=weirdness[];Do[L=weirdness[L,i],{i,1}]],{L\$19=\
weirdness\$19[];Do[L\$19=weirdness\$19[L\$19,

i],{i,1}],{L\$19=weirdness\$19[],weirdness\$19[]},{Do[L\$19=weirdness\$19[L\$\
19,i],{i,1}],{{{L\$19,weirdness\$19[]},{i,1},weirdness\$19[weirdness\$19[],

1]},L\$19=weirdness\$19[weirdness\$19[],1],weirdness\$19[weirdness\$19[],1]\
},Null},Null},Null}

in any case all these numbers are larger than 10 and produce slowdown,
but the numbers 10-16 which never occur inside Module also suffer form
this problem:

In[3]:=
L=weirdness\$11[];
Do[L=weirdness\$11[L,i],{i,10^4}]//Timing

Out[4]=
{13.1 Second,Null}

In[5]:=
L=weirdness\$16[];
Do[L=weirdness\$16[L,i],{i,10^4}]//Timing

Out[6]=
{14.62 Second,Null}

However, I have not been able to find any other name but weirdness that
produces this effect. This seems weird.

Andrzej Kozlowski

On 3 Jan 2005, at 18:29, yehuda ben-shimol wrote:

> Hi Roland,
> I'm afraid this is not true. Just try to run the code I sent with my
> post.  "weirdness" was time consuming while weirdness1 was not. In
> addition it happened (not consistently) that function name of a SINGLE
> character suffered from this behavior as well.
> the code is given below for your convenience.
>
> t = CharacterRange["a", "z"];
> Do[fname = StringJoin[t[[Table[Random[Integer, {1,26}], {i}]]]];
> Print[i, "\t", fname, "\t",
> 	Timing[
> 	  Module[{fs = ToExpression[fname], L},
>           L = fs[];
>         Do[L = fs[L, j], {j, 104}]]]], {i, 1, 50}, {5}]
>
>
> yehuda
>
> Roland Franzius wrote:
>
>> Maxim wrote:
>>
>>
>>> Consider:
>>>
>>> In[1]:=
>>> Module[{f, L},
>>>   L = f[];
>>>   Do[L = f[L, i], {i, 10^4}]
>>> ] // Timing
>>>
>>> Module[{weirdness, L},
>>>   L = weirdness[];
>>>   Do[L = weirdness[L, i], {i, 10^4}]
>>> ] // Timing
>>>
>>> Out[1]=
>>> {0.015*Second, Null}
>>>
>>> Out[2]=
>>> {3.063*Second, Null}
>>>
>>> Here the timings differ by a factor of 200. Besides, the timing grows
>>> linearly in the first case and quadratically in the second
>>> (therefore, for
>>> n=10^5 there will be an approximately 2000 times slowdown). We can
>>> only
>>> guess that something goes wrong with the symbol name hashing.
>>>
>>>
>>
>> The timing difference occurs when the symbol "wierdness" exceeds 8
>> characters. Test it for "wierdnes". That seems to be a consequence of
>> the machine routine for string comparison. Up to 8 characters can be
>> used without using a memory to memory compare. Of course it should be
>> possible to write a compare routine that makes not such a bit step.
>>
>

```

• Prev by Date: shuffling 10^8 numbers
• Next by Date: Re: Re: Re: Slowdown
• Previous by thread: Re: Re: Slowdown
• Next by thread: Re: Re: Re: Slowdown