Regarding array size and speed...

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

voyagerOne
Posts: 154
Joined: Tue May 17, 2011 8:12 pm

Regarding array size and speed...

Post by voyagerOne »

In my engine I have implemented plain Magic bitboard. I am curious on what performance I can expect if I use condense Fancy magic.

I realize its highly dependent on hardware...but just looking for a general ballpark of expected speed or ratio.

A related question...(this may be a dumb question)

But I am having difficult time of calculating mem sizes in arrays.
U64 mRookAttacks [64][4096]; // 2048K

My logic is 64 bits * 64 * 4096 = 16777216
16777216/8000=2097.152 KB

What am I doing wrong here?
Thanks in advance.
bhlangonijr
Posts: 482
Joined: Thu Oct 16, 2008 4:23 am
Location: Milky Way

Re: Regarding array size and speed...

Post by bhlangonijr »

16777216/8000=2097.152 KB

What am I doing wrong here?
Thanks in advance.
64/8 * 64 * 4096 = 2097.152 bytes

2097.152/1024 = 2048 KB

Is that what you mean?

Regards,
voyagerOne
Posts: 154
Joined: Tue May 17, 2011 8:12 pm

Re: Regarding array size and speed...

Post by voyagerOne »

So 1KB = 1024 Bytes?

Also..both your formulas are off by a factor of 1000... not sure if that was intentional.

Bill
bhlangonijr
Posts: 482
Joined: Thu Oct 16, 2008 4:23 am
Location: Milky Way

Re: Regarding array size and speed...

Post by bhlangonijr »

voyagerOne wrote:
So 1KB = 1024 Bytes?
Yes, at least it used to be. :)
The multiples of the byte unit are power of 2: 2^10 bytes=1KB, 2^20 bytes = 1MB, etc...
Also..both your formulas are off by a factor of 1000... not sure if that was intentional.

Bill
I would suggest you reading a good book about programming and computer basics in case you are not very familiar with it.

http://www.htdp.org/

Regards,
User avatar
michiguel
Posts: 6401
Joined: Thu Mar 09, 2006 8:30 pm
Location: Chicago, Illinois, USA

Re: Regarding array size and speed...

Post by michiguel »

bhlangonijr wrote:
voyagerOne wrote:
So 1KB = 1024 Bytes?
Yes, at least it used to be. :)
But it is not anymore!
Kilobyte = 1000 bytes
Kibibytes = 1024 bytes.

But programmers keep murdering the metric system.
http://en.wikipedia.org/wiki/Binary_prefix

At least it is not gallons, inches, or any of that crap :-)
Miguel

The multiples of the byte unit are power of 2: 2^10 bytes=1KB, 2^20 bytes = 1MB, etc...
Also..both your formulas are off by a factor of 1000... not sure if that was intentional.

Bill
I would suggest you reading a good book about programming and computer basics in case you are not very familiar with it.

http://www.htdp.org/

Regards,
bhlangonijr
Posts: 482
Joined: Thu Oct 16, 2008 4:23 am
Location: Milky Way

Re: Regarding array size and speed...

Post by bhlangonijr »

michiguel wrote:
But it is not anymore!
Kilobyte = 1000 bytes
Kibibytes = 1024 bytes.

But programmers keep murdering the metric system.
http://en.wikipedia.org/wiki/Binary_prefix

At least it is not gallons, inches, or any of that crap :-)
Miguel
As the twig is bent, so is the tree inclined... :)
micron
Posts: 155
Joined: Mon Feb 15, 2010 9:33 am
Location: New Zealand

Re: Regarding array size and speed...

Post by micron »

voyagerOne wrote:In my engine I have implemented plain Magic bitboard. I am curious on what performance I can expect if I use condense Fancy magic.
I realize its highly dependent on hardware...but just looking for a general ballpark of expected speed or ratio.
The table below is from this thread:
http://www.talkchess.com/forum/viewtopi ... ew=threads

Code: Select all

Times in ms for nominal 11 ply search with different BitBoard slider attack generators. 
In each case a preliminary "warmup" run0 was discarded. 

                            KB   run1 run2 run3    minimum 
plain magic (fixed-shift) 2304   3755 3756 3755    3755 
fancy magic*               840   3764 3764 3762    3762 
plain magic (var-shift)   2304   3810 3811 3810    3810 
classic BB (branch-free)     4   4381 4381 4381    4381 
classic BB                   4   4871 4867 4867    4867 

*from Crafty
Robert P.
voyagerOne
Posts: 154
Joined: Tue May 17, 2011 8:12 pm

Re: Regarding array size and speed...

Post by voyagerOne »

Last edited by voyagerOne on Sun Sep 25, 2011 4:45 am, edited 1 time in total.
voyagerOne
Posts: 154
Joined: Tue May 17, 2011 8:12 pm

Re: Regarding array size and speed...

Post by voyagerOne »

Code: Select all

import java.util.Random;

class test
{
	static Random generator=new Random();
	
        static byte[] bigArray=new byte[3200000];
        static int[] bigArray=new int[3200000];
        static long[] bigArray=new long[3200000];

	public static void main(String args[])
	{
		popArr();
		long time=System.currentTimeMillis();
		func();
		System.out.println(System.currentTimeMillis() - time);
	}


	static void func()
	{
		int n=bigArray.length;

		for &#40;int i=0; i < 100000000; i++)
		&#123;
			if &#40;bigArray&#91;generator.nextInt&#40;n&#41;&#93; == -1&#41;
			&#123;
				System.out.println&#40;"this should not happen");
				break;
			&#125;
		&#125;
	&#125;

	static void popArr&#40;)
	&#123;
		for &#40;int i=0; i < bigArray.length; i++)
		&#123;
			bigArray&#91;i&#93;=generator.nextInt&#40;255&#41;;
		&#125;

	&#125;
&#125;


Did a little a experiment...

Here are the results.

Byte=3065 ms
int=5500 ms
long=7422 ms
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Regarding array size and speed...

Post by mcostalba »

voyagerOne wrote: What am I doing wrong here?
Sorry, please do not take it personally, but I am really curious to know why beginners in computer chess / computer programming try to _optimize_ the stuff they write before to build up a working engine ?

I have read many times of people that is worried by a possible 2% speed increment or something similar when still misses a working alpha-beta searcher.

Could you please elaborate on why you are trying to optimize your functions before to have a working engine ? And with working I mean that is able to play legal chess in matches.