Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8144573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:25:30+00:00 2026-06-06T13:25:30+00:00

For some reason, my method bishops runs much faster when called from the main

  • 0

For some reason, my method “bishops” runs much faster when called from the main method than from the static initialization block. Is this normal, or a bug?

public class Magic
{
    public static void main(String[] args)
    {
        bishops();
    }

    public static void bishops()
    {
        //PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("bishops.txt")));
        BISHOP_SHIFTS = new int[64];
        BISHOP_COMBOS = new long[64][];
        for (int square = 0; square < 64; square++) {System.out.println("bbb " + square);
            int NUMBER = bitCount(BISHOP_ATTACKS[square]);
            BISHOP_SHIFTS[square] = 64 - NUMBER;
            long x = BISHOP_ATTACKS[square];
            long[] MAPS = new long[NUMBER];
            for (int n = 0; n < NUMBER; n++) {
                int i = bitScan(x);
                MAPS[n] = (1L << i);
                x -= MAPS[n];
            }
            int C = 1 << NUMBER;
            BISHOP_COMBOS[square] = new long[C];
            for (int i = 0; i < C; i++) {
                BISHOP_COMBOS[square][i] = 0;
                int j = i;
                for (int n = 0; n < NUMBER; n++) {
                    if ((j & 1) == 1)
                        BISHOP_COMBOS[square][i] |= MAPS[n];
                    j >>>= 1;
                }
                //out.println("SQUARE " + square);
                //out.println(toBitboardString(BISHOP_COMBOS[square][i]));
                //out.println();
            }
        }
        //out.close();

        bishopMagics();
    }

    public static void bishopMagics()
    {
        BISHOP_MAGICS = new long[64];
        Random r = new Random();

        for (int square = 0; square < 64; square++) {System.out.println("asdffff " + square);
            int i;
            int LENGTH = BISHOP_COMBOS[square].length;
            long magic;
            do {
                magic = r.nextLong() & r.nextLong() & r.nextLong();
                //final int COUNT = bitCount(BISHOP_MASKS[square]);
                boolean[] used = new boolean[LENGTH];
                for (int j = 0; j < used.length; j++)
                    used[j] = false;
                for (i = 0; i < LENGTH; i++) {
                    int index = (int) ((BISHOP_COMBOS[square][i] * magic) >>> BISHOP_SHIFTS[square]);
                    if (used[index])
                        break;
                    else
                        used[index] = true;
                }
            } while (i < LENGTH);
            BISHOP_MAGICS[square] = magic;
            System.out.println(magic);
        }

        //bishopTable();
    }

    /*
     * Lots of stuff omitted
     */

    static
    {
        //bishops();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T13:25:31+00:00Added an answer on June 6, 2026 at 1:25 pm

    It will run much faster the second time than the first as the JVM warms up (loads class es and compiles code). The static block is always called first.

    Try running it twice from the main() or the static block and see how long it takes each time

    BTW: I would take out any logging to the console as this can slow down the code dramatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My animationDidStop method is not being called for some reason, initially I thought it
Both methods MyBehavior::CreateSerializer() are not called of some reason, but ReplaceBehavior() method is working.
what this method will return when the db is null for some reason? compile
I wrote this HttpRequest method, but for some reason it always goes to 404
I am implementing a protocol that has a method called fbDidExtendToken:. For some reason,
For some reason the LoadContent method does not get called in my Components. For
For some reason the onpause method is not always getting called when my app
For some reason, my paintComponent(Graphics g) method is being called infinitely. I can't seem
for some reason I'm thinking on implementing interface within a some function(method) as local
In the method below titleForHeaderInSection , for some reason the NSLog prints out the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.