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

106
Views
¿Hay alguna manera de segmentar los bucles para que sean más eficientes?

Actualmente estoy creando un juego con JavaScript, y estoy tratando de hacer un bucle for más rápido, ya que hay grandes mundos generados aleatoriamente, y preferiría hacerlos onload, tal vez en una pantalla de carga. Hace un tiempo, hice este código:

 colorMode(3); background(255); noStroke(); frameRate(0); var x = 0; var y = 0; var offX = 0; var offY = 0; var chunkSize = 81; var gen = 1; var s = millis(); draw = function() { while (x < offX + chunkSize) { while (y < offY + chunkSize) { fill((x + y) / 3, 255, 255); rect(x, y, gen, gen); y += gen; } y = offY; x += gen; } offX += chunkSize - 1; if (offX >= width) { offY += chunkSize - 1; offX = 0; } if (offY >= height) { offY = 0; offX = 0; if (gen > 1) { gen = round(gen - 1); } else { println("Finished. Took " + (millis() - s) + "ms"); noLoop(); } } x = offX; y = offY; };

en la Academia Khan. Lo hizo mucho más rápido que si solo tuviera que hacer:

 var x = 0; var y = 0; while (x < width) { while (y < height) { point(x, y); ++y; } ++x; }

Que, a juzgar por este enlace, debería ser el más rápido. Técnicamente lo es, pero es lento y algo lento. Quiero replicarlo, pero estoy teniendo problemas. Posiblemente porque esta vez será en 3D. Probablemente podría recrearlo nuevamente en 2D, pero no estoy seguro. El código más nuevo con el que tengo problemas es

 let x, y, z; let size = 10000; let world = []; while(x < size){ world[x] = []; while(y < size){ world[x][y] = []; while(z < size){ world[x][y][z] = Math.random(); ++z; } ++y; } ++x; }
about 4 years ago · Juan Pablo Isaza
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!