1. 程式人生 > 其它 >js獲取一個函式執行時間

js獲取一個函式執行時間

技術標籤:jsjs

關鍵詞:時間戳

這裡隨便瞎寫了個for迴圈10000次向arr中新增內容


        let arr = []

        function testFun() {
            let start = new Date().getTime()
            for (let index = 0; index < 10000; index++) {
                arr.push(index)
                // ...Do something
            }
            let end = new Date().getTime()
            console.log("開始:", start)
            console.log("結束:", end)
            
            console.log("花費:", end - start)
        }

        testFun()