Skip to main content
added 769 characters in body
Source Link
Constantin
  • 151
  • 1
  • 6
//=========================================================================                                     
// MOVE INFO                                                                                                    
//=========================================================================                                     
public static final int MOVE_INFO_COUNT = 19;                                                                   
public static final int MOVE_INFO_EXTRA_1 = 0;                          // -> ACTIVE DIGIT IS ALWAYS 1          
public static final int MOVE_INFO_EXTRA_2 = 1;                          // -> UNUSED (0)                        
public static final int MOVE_INFO_EXTRA_3 = 2;                          // -> UNUSED (0)                        
public static final int MOVE_INFO_PLAYER = 3;                           // -> PLAYER CONSTANTS (0 - 1)          
public static final int MOVE_INFO_MOVE_TYPE = 4;                        // -> MOVE-TYPE CONSTANTS (0 - 8)       
public static final int MOVE_INFO_MOVED_PIECE = 5;                      // -> PIECE CONSTANTS (0 - 6)           
public static final int MOVE_INFO_SOURCE_ROW = 6;                       // -> RANK (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_SOURCE_COL = 7;                       // -> FILE (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_TARGET_ROW = 8;                       // -> RANK (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_TARGET_COL = 9;                       // -> FILE (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_CAPTURED_PIECE = 10;                  // -> PIECE CONSTANTS (0 - 6)           
public static final int MOVE_INFO_EN_PASSANT_ROW = 11;                  // -> RANK (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_EN_PASSANT_COL = 12;                  // -> FILE (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_PREVIOUS_EN_PASSANT_ROW = 13;         // -> RANK (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_PREVIOUS_EN_PASSANT_COL = 14;         // -> FILE (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_WHITE_CASTLING_RIGHTS = 15;           // -> CASTLING-RIGHTS CONSTANTS (0 - 3) 
public static final int MOVE_INFO_BLACK_CASTLING_RIGHTS = 16;           // -> CASTLING-RIGHTS CONSTANTS (0 - 3) 
public static final int MOVE_INFO_PREVIOUS_WHITE_CASTLING_RIGHTS = 17;  // -> CASTLING-RIGHTS CONSTANTS (0 - 3) 
public static final int MOVE_INFO_PREVIOUS_BLACK_CASTLING_RIGHTS = 18;  // -> CASTLING-RIGHTS CONSTANTS (0 - 3)  


import com.chess.engine.Move;
public class DEBUG_ENCODE_DECODE {

    private static final void benchmark(long iterations) {
        long start = System.currentTimeMillis();
        long counter = 0;
        for(long i = 0L; i < iterations; i++) {
            work();
            counter++;
        }
        long end = System.currentTimeMillis();
        System.out.println(counter +" ITERATIONS IN MILLISECONDS: " + (end - start));
    }

    private static final void work() {
        long move = 1000432101234567890L;
    
        if(Move.encodeMove(Move.decodeMove(move)) != move) {
            throw new RuntimeException("ENCODE DECODE FAILED");
        }
    }

    public static void main(String[] args) {
        benchmark(100000000);
    }
}
//=========================================================================                                     
// MOVE INFO                                                                                                    
//=========================================================================                                     
public static final int MOVE_INFO_COUNT = 19;                                                                   
public static final int MOVE_INFO_EXTRA_1 = 0;                          // -> ACTIVE DIGIT IS ALWAYS 1          
public static final int MOVE_INFO_EXTRA_2 = 1;                          // -> UNUSED (0)                        
public static final int MOVE_INFO_EXTRA_3 = 2;                          // -> UNUSED (0)                        
public static final int MOVE_INFO_PLAYER = 3;                           // -> PLAYER CONSTANTS (0 - 1)          
public static final int MOVE_INFO_MOVE_TYPE = 4;                        // -> MOVE-TYPE CONSTANTS (0 - 8)       
public static final int MOVE_INFO_MOVED_PIECE = 5;                      // -> PIECE CONSTANTS (0 - 6)           
public static final int MOVE_INFO_SOURCE_ROW = 6;                       // -> RANK (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_SOURCE_COL = 7;                       // -> FILE (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_TARGET_ROW = 8;                       // -> RANK (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_TARGET_COL = 9;                       // -> FILE (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_CAPTURED_PIECE = 10;                  // -> PIECE CONSTANTS (0 - 6)           
public static final int MOVE_INFO_EN_PASSANT_ROW = 11;                  // -> RANK (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_EN_PASSANT_COL = 12;                  // -> FILE (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_PREVIOUS_EN_PASSANT_ROW = 13;         // -> RANK (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_PREVIOUS_EN_PASSANT_COL = 14;         // -> FILE (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_WHITE_CASTLING_RIGHTS = 15;           // -> CASTLING-RIGHTS CONSTANTS (0 - 3) 
public static final int MOVE_INFO_BLACK_CASTLING_RIGHTS = 16;           // -> CASTLING-RIGHTS CONSTANTS (0 - 3) 
public static final int MOVE_INFO_PREVIOUS_WHITE_CASTLING_RIGHTS = 17;  // -> CASTLING-RIGHTS CONSTANTS (0 - 3) 
public static final int MOVE_INFO_PREVIOUS_BLACK_CASTLING_RIGHTS = 18;  // -> CASTLING-RIGHTS CONSTANTS (0 - 3) 
//=========================================================================                                     
// MOVE INFO                                                                                                    
//=========================================================================                                     
public static final int MOVE_INFO_COUNT = 19;                                                                   
public static final int MOVE_INFO_EXTRA_1 = 0;                          // -> ACTIVE DIGIT IS ALWAYS 1          
public static final int MOVE_INFO_EXTRA_2 = 1;                          // -> UNUSED (0)                        
public static final int MOVE_INFO_EXTRA_3 = 2;                          // -> UNUSED (0)                        
public static final int MOVE_INFO_PLAYER = 3;                           // -> PLAYER CONSTANTS (0 - 1)          
public static final int MOVE_INFO_MOVE_TYPE = 4;                        // -> MOVE-TYPE CONSTANTS (0 - 8)       
public static final int MOVE_INFO_MOVED_PIECE = 5;                      // -> PIECE CONSTANTS (0 - 6)           
public static final int MOVE_INFO_SOURCE_ROW = 6;                       // -> RANK (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_SOURCE_COL = 7;                       // -> FILE (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_TARGET_ROW = 8;                       // -> RANK (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_TARGET_COL = 9;                       // -> FILE (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_CAPTURED_PIECE = 10;                  // -> PIECE CONSTANTS (0 - 6)           
public static final int MOVE_INFO_EN_PASSANT_ROW = 11;                  // -> RANK (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_EN_PASSANT_COL = 12;                  // -> FILE (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_PREVIOUS_EN_PASSANT_ROW = 13;         // -> RANK (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_PREVIOUS_EN_PASSANT_COL = 14;         // -> FILE (0 - 7) OR 9 = NOT APPLICABLE
public static final int MOVE_INFO_WHITE_CASTLING_RIGHTS = 15;           // -> CASTLING-RIGHTS CONSTANTS (0 - 3) 
public static final int MOVE_INFO_BLACK_CASTLING_RIGHTS = 16;           // -> CASTLING-RIGHTS CONSTANTS (0 - 3) 
public static final int MOVE_INFO_PREVIOUS_WHITE_CASTLING_RIGHTS = 17;  // -> CASTLING-RIGHTS CONSTANTS (0 - 3) 
public static final int MOVE_INFO_PREVIOUS_BLACK_CASTLING_RIGHTS = 18;  // -> CASTLING-RIGHTS CONSTANTS (0 - 3)  


import com.chess.engine.Move;
public class DEBUG_ENCODE_DECODE {

    private static final void benchmark(long iterations) {
        long start = System.currentTimeMillis();
        long counter = 0;
        for(long i = 0L; i < iterations; i++) {
            work();
            counter++;
        }
        long end = System.currentTimeMillis();
        System.out.println(counter +" ITERATIONS IN MILLISECONDS: " + (end - start));
    }

    private static final void work() {
        long move = 1000432101234567890L;
    
        if(Move.encodeMove(Move.decodeMove(move)) != move) {
            throw new RuntimeException("ENCODE DECODE FAILED");
        }
    }

    public static void main(String[] args) {
        benchmark(100000000);
    }
}
edited title; edited tags
Link
200_success
  • 145.6k
  • 22
  • 191
  • 481

Critical encoding Encoding and decoding functionsan array of digits

deleted 17 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Improve performance of critical Critical encoding and decoding functions

I have two simple functions where performance is critical, one for encoding an array of intsints to a long, another for doing the opposite (decoding the long back to an array of intsints).

The solutions I have come up with below are fairly fast but my question is can. Can these be made even faster?

PLEASE NOTEPlease note: I AM CONSTRAINED BY USING THE SAME FUNCTION SIGNATURES. I am constrained by using the same function signatures.

Improve performance of critical encoding and decoding functions

I have two simple functions where performance is critical, one for encoding an array of ints to a long, another for doing the opposite (decoding the long back to an array of ints).

The solutions I have come up with below are fairly fast but my question is can these be made even faster?

PLEASE NOTE: I AM CONSTRAINED BY USING THE SAME FUNCTION SIGNATURES.

Critical encoding and decoding functions

I have two simple functions where performance is critical, one for encoding an array of ints to a long, another for doing the opposite (decoding the long back to an array of ints).

The solutions I have come up with below are fairly fast. Can these be made even faster?

Please note: I am constrained by using the same function signatures.

Post Migrated Here from stackoverflow.com (revisions)
Source Link
Constantin
  • 151
  • 1
  • 6
Loading