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

122
Vistas
Why does performance.now differ so much from console.time?

I've just made a quick sort algorithm in javascript and now want to time it. My first approach was with console.time and console.timeEnd but after reading around a little I found out that performance.now is the better option. Only thing is that they're giving me wildly different results as you can see below:

script.js:89 performance.now: 5.099999904632568 ms
script.js:93 console.time: 1.091796875 ms

Now some of the results are better than others but most of the time there are differences of up to 5 ms. Is this just my computer behaving differently each time or am I using the methods wrong?

Here's the code:

let startTime = performance.now();
quickSort(randomArray);
let endTime = performance.now();
console.log(`performance.now: ${endTime - startTime} ms`);

console.time("console.time");
quickSort(randomArray);
console.timeEnd("console.time");

The sorting algorithm if needed:

function quickSort(array) {
    quickSortSplit(array, 0, array.length - 1);
    return array;
}

function quickSortSplit(array, low, high) {
    if (low < high) {
        let finalIndex = partition(array, low, high);

        quickSortSplit(array, low, finalIndex - 1);
        quickSortSplit(array, finalIndex + 1, high);
    }
}

function partition(array, low, high) {
    let pivotIndex = medianOfThree(array, low, high);
    let pivot = array[pivotIndex];
    array.swap(pivotIndex, high);

    let i = low - 1;
    for (let j = low; j < high; j++) {
        if (array[j] <= pivot) {
            i++;
            array.swap(j, i);
        }
    }
    array.swap(i + 1, high);
    return i + 1;
}
about 4 years ago · Juan Pablo Isaza
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