Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

190
Visualizações
timing in Javascript acting strange

I am working on js to compare the performance of brute force O(n^2) and Barnes-Hut O(nlog(n))

In my code right now I am doing the same thing with the same data five times

like this:

let data = [arrays of 100 data];
let count = 5;
while(count>0){
  count--;
  console.time('brute force time' + iterationCount);
  brute force function()
  console.timeEnd('brute force time' + iterationCount);

  console.time('BH time' + iterationCount );
  Barnes Hut algorithm();
  console.timeEnd('BH time' + iterationCount);
 }
}

Though, the code is the same for each time, console.time is showing the different and worrying results.

enter image description here

In the timing, the difference between BH and brute force is not relatively similar in multiple iterations. and it is not predictable when I run code every time.

One more thing to notice is that every time I run the code, in the first iteration brute force and Barnes Hut algorithm timing are almost similar where as after first, it shows that Barnes-Hut is way better.

PS: everything in both functions is scoped to each function i.e local variable and shares the same data in each iteration so in each iteration code is identical !!!!

can anyone help me understand why I am getting like this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I'd guess these times are so tiny random noise affects the results - your machine doing other processing perhaps. I'd increase the data size, and therefore the processing time - maybe you'd see more consistent results then.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda