[英]How to get the output from console.timeEnd() in JS Console?
[英]How to show result of console.timeEnd() in react native android app?
我已經安裝了軟件包並將其導入為:
import 'react-native-console-time-polyfill';
並具有以下功能:
search = () => {
let s = this.state.file.toLowerCase();
let p = this.state.search.toLowerCase();
console.time('t');
let result = kmp.findAll(s, p);
let time = console.timeEnd('t');
alert(time);
};
為什么警報的結果返回為“ undefined”?
我希望處理功能的結果時間顯示在警報彈出窗口中。 搜索是按一下按鈕時的功能。
對不起,我的英語不好,希望你們能理解我的問題^^
您正在使用的庫的編寫方式,它僅將結果時間輸出到控制台,而不返回它。 因此,盡管您可以在調試控制台中看到它,但是您將始終從.time()
和.timeEnd()
函數接收undefined
.time()
。 對於瀏覽器也是如此,您實際上可以在Javascript控制台中對其進行測試。
但是該庫的代碼似乎很短,您實際上可以添加功能。 如果添加return delta.toFixed(3);
在.timeEnd()
函數的.timeEnd()
index.js中的第21行),您可以獲得所需的結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.