#CutLongStoryShort

Mierzenie czasu wykonywania funkcji (wraz z przekazaniem parametru funkcji) oraz wyświetlenie owego czasu w konsoli.

const measureFunction = (functionReference, name = "functionReference", param) => {
    console.time(name)

    if (typeof param !== 'undefined') {
        functionReference(param)
    } else {
        functionReference()
    }

    console.timeEnd(name)
}

// function
const myFunction = (text) => {
    console.log(text)
}

const mySecondFunction = () => {
    console.log("This is mySecondFunction")
}

// using
measureFunction(myFunction,'myFunctionName', 'hello, world')
measureFunction(mySecondFunction ,'mySecondFunction')

Output:

/*
hello, world
myFunctionName: 0.285888671875 ms
This is mySecondFunction
mySecondFunction: 0.293212890625 ms
*/