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

134
Views
Tiempo de ejecución de Python vs Javascript

Intenté resolver Maximum Subarray usando Javascript (Node.js) y Python, con un algoritmo de fuerza bruta. Aquí está mi código:

Usando pitón:

 from datetime import datetime from random import randint arr = [randint(-1000,1000) for i in range(1000)] def bruteForce(a): l = len(a) max = 0 for i in range(l): sum = 0 for j in range(i, l): sum += a[j] if(sum > max): max = sum return max start = datetime.now() bruteForce(arr) end = datetime.now() print(format(end-start))

Y JavaScript:

 function randInt(start, end) { return Math.floor(Math.random() * (end - start + 1)) } var arr = Array(1000).fill(randInt(-1000, 1000)) function bruteForce(arr) { var max = 0 for (let i = 0; i < arr.length; i++) { var sum = 0 for (let j = i; j < arr.length; j++) { sum += arr[j] max = Math.max(max, sum) } } return max } var start = performance.now() bruteForce(arr) var end = performance.now() console.log(end - start)

Javascript obtuvo un resultado de aproximadamente 0,187 segundos, mientras que Python obtuvo 4,75 segundos, unas 25 veces más lento. ¿Mi código no está optimizado o Python es realmente más lento que JavaScript?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Sí, lo es. Todos los motores JS modernos son bastante rápidos y significativamente más rápidos que Python. Pero eso no siempre importa, el contexto es importante a la hora de decidir entre idiomas en función del rendimiento.

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!