mardi 30 novembre 2021

java: too many cases makes performance drop [closed]

So for example I have code like this

String input;

switch(input){
   case "a": // do a process break;
   case "b": // do a process break;
   ... until around 40 functions
}

each process is unique. Simple example of the file

a
b
c
a
b

so the problem with performance is like this I use that function to read a file (that function run 20000 times).

when I run switch for 30 cases (comment 10 cases) the time is (assume) 30s
when I run switch for 35 cases (comment 5 cases) the time become 50s
when I run switch for 40 cases the time also become 50s
all of the 3 use same input that 10 commented cases is not exist in input

I am curious why there is a jump in that processing time and actually I also tried by using 30 cases which is 30s I added this code

// after the code above    
boolean temp = false;
if(temp){ // do nothing }

and the processing time is jump into 50s so the processing time is always jump from 30s to 50s when I add any if function except if(true){} or if (false){} but after it jump into 50s, it become stable in 50ish again

I wonder if java has some kind of memory allocation that affect this behaviour I tried to increase heap memory -Xmx but the result is still the same

Aucun commentaire:

Enregistrer un commentaire