I've been making a chess engine and I'm writing evaluation function and this is some part:
List<Double> eval;
switch (name) {
    case "PAWN":
        eval = new ArrayList<>(pawnEval);
        if (color == -1)
            Collections.reverse(eval);
        evaluation += (PAWN + eval.get(count)) * color;
        break;
    case "KNIGHT":
        eval = new ArrayList<>(knightEval);
        if (color == -1)
            Collections.reverse(eval);
        evaluation += (KNIGHT + eval.get(count)) * color;
        break;
    case "BISHOP":
        eval = new ArrayList<>(bishopEval);
        if (color == -1)
            Collections.reverse(eval);
        evaluation += (BISHOP + eval.get(count)) * color;
        break;
    case "ROOK":
        eval = new ArrayList<>(rookEval);
        if (color == -1)
            Collections.reverse(eval);
        evaluation += (ROOK + eval.get(count)) * color;
        break;
    case "QUEEN":
        eval = new ArrayList<>(queenEval);
        if (color == -1)
            Collections.reverse(eval);
        evaluation += (QUEEN + eval.get(count)) * color;
        break;
    case "KING":
        eval = new ArrayList<>(kingEval);
        if (color == -1)
            Collections.reverse(eval);
        evaluation += (KING + eval.get(count)) * color;
        break;
}
Creating another function and putting that code in it will cost less time than putting it directly in evaluation function so I tried putting that switch statement into a pieceEval method so it will just look like this:
evaluation += pieceEval(...) * color;
Before:
2876 total time (ms)
231786 nodes
After:
2184 total time (ms)
231786 nodes
My main question is: Does it really speed up code when extracting lines of codes into a method instead fitting it in one?
 
    