Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

197
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda