Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!