Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Programming question.

Author: Bruce Moreland

Date: 14:58:14 03/19/99

Go up one level in this thread



On March 19, 1999 at 16:06:10, Inmann Werner wrote:

>Hello.
>
>Today I changed my hashtables from fixed one ta allocated one.
>
>Example
>Old
>
>long hindex[65536]
>signed char hcolor[65536]
>signed short int value[65536]
>.....
>
>New
>
>long *hindex
>signed char *hcolor
>signed short int *value
>....
>
>hindex=malloc(4*65536)
>hcolor=malloc(65536)
>value=malloc(2*65536)
>....
>
>Works fine but:
>
>On my P90, the NPS decreases about 30%  !!!!!
>On my Cyrix 233 everything is fine (same speed)
>
>Do I anything extremly wrong or what happens here. Has this something to do
>with Prozessor cache or what?

A suggestion that won't change anything is that you change the 4 and 2 to
sizeof(long) and sizeof(short) respectively.  That might prevent you from
getting bit at some point.

"long * hindex" and "long hindex[65536]" aren't the same thing to the compiler.
When the compiler wants to resolve hindex[i] in the first case, it has to load a
value from memory, and add i * 4 to it.  In the second case it adds i * 4 to a
constant that the compiler already knows.  So there is some inefficiency built
into that.

But 30%?  No way.  Something else has to be happening.  Are you sure you are
checking the speed properly?  Run the old version, then the new version, then
the old version, then the new version.  You should see slow, fast, slow, fast.

You could put those three fields into a structure at some point as well.  That
is more "C" and it should be faster, although there is no guarantee.

Sorry if this doesn't help, but it's hard to guess what this could be.

bruce



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.