How to increase processing capacity in Javascript?

Asked

Viewed 16 times

0

Hello, I have a javascript application that generate random rounds of a football championship (turn and return). However, to assemble the rounds in a combination that does not repeat the same team in the same round and two teams can only play once per turn between themselves, so I used several loops and functions to filter.

Already working perfectly, however, up to 16 times works. When I put more than 16 times the browser hangs (is on hold.. and closes). Are there any processing limits for Javascript? You can avoid this error and put more teams?

  function gerarRodadas()
  {
       qtd_total_partidas = this.arrPartidas.length;
       qtd_rodadas = (this.arrTimes.length-1)*2;
       qtd_partidas_por_rodada = this.arrTimes.length/2;

       arr_pos = new Array(qtd_total_partidas); 
       iniciarArray(arr_pos, qtd_total_partidas);

       for(i=0; i<qtd_rodadas; i++)
       {   

             cond=0; //so é atualizado se for possível inserir a partida na rodada
             pos=0;

             //Completar todas as partidas por rodada
             while(cond < qtd_partidas_por_rodada)
            {
              if(pos == qtd_total_partidas)
              {
                pos=0;
              }

              if(arr_pos[pos] == 0) 
              {
                if(verificarRodada(i, this.arrRodadas, this.arrPartidas[pos]))
                {
                  if(verificarTurno(i, this.arrRodadas, this.arrPartidas[pos], qtd_rodadas/2))
                  { 
                    mandante = this.arrPartidas[pos].mandante;
                    visitante = this.arrPartidas[pos].visitante;
                    estado = this.arrPartidas[pos].estado;                  

                    res1 = Math.floor(Math.random() * 6);
                    res2 = Math.floor(Math.random() * 6);

                    rodDupla = verificarRodadaDupla(i, estado, this.arrRodadas);

                    this.arrRodadas.push({rodada:i, mandante: mandante, visitante:visitante, estado: estado, resMandante: res1, resVisitante: res2, rodadaDupla: rodDupla});
                    arr_pos[pos] = 1;    
                    cond++;
                  }
                 }
               }
               pos++;
             }
        }

  }
  • Either it is unclear what you want or you already have questions about it: https://answall.com/q/10282/101 Almost all performance problems are solved by studying algorithms and data structures. My definition of perfectly is different, perfect has no problems, which gives problem is not perfect. 99.999% of the time the problem is not the technology used but the code of the person.

  • Related: https://answall.com/questions/56836/defini%C3%A7%C3%a3o-da-nota%C3%A7%C3%a3o-big-o

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.