diff --git a/src/components/Debug.tsx b/src/components/Debug.tsx index 2469fb78..bb7afc80 100644 --- a/src/components/Debug.tsx +++ b/src/components/Debug.tsx @@ -11,6 +11,10 @@ const Debug: React.FC = () => { const [cipher04, setCipher04] = useState('') const [plain44, setPlain44] = useState('') const [plain04, setPlain04] = useState('') + const [tEncrypt44, setTEncrypt44] = useState(null) + const [tEncrypt04, setTEncrypt04] = useState(null) + const [tDecrypt44, setTDecrypt44] = useState(null) + const [tDecrypt04, setTDecrypt04] = useState(null) const [logs, setLogs] = useState(DebugBus.snapshot()) const [debugEnabled, setDebugEnabled] = useState(() => localStorage.getItem('debug') === '*') @@ -29,10 +33,14 @@ const Debug: React.FC = () => { try { const api = (signer as any)[mode] DebugBus.info('debug', `encrypt start ${mode}`, { pubkey, len: payload.length }) + const start = performance.now() const cipher = await api.encrypt(pubkey, payload) - DebugBus.info('debug', `encrypt done ${mode}`, { len: typeof cipher === 'string' ? cipher.length : -1 }) + const ms = Math.round(performance.now() - start) + DebugBus.info('debug', `encrypt done ${mode}`, { len: typeof cipher === 'string' ? cipher.length : -1, ms }) if (mode === 'nip44') setCipher44(cipher) else setCipher04(cipher) + if (mode === 'nip44') setTEncrypt44(ms) + else setTEncrypt04(ms) } catch (e) { DebugBus.error('debug', `encrypt error ${mode}`, e instanceof Error ? e.message : String(e)) } @@ -48,10 +56,14 @@ const Debug: React.FC = () => { return } DebugBus.info('debug', `decrypt start ${mode}`, { len: cipher.length }) + const start = performance.now() const plain = await api.decrypt(pubkey, cipher) - DebugBus.info('debug', `decrypt done ${mode}`, { len: typeof plain === 'string' ? plain.length : -1 }) + const ms = Math.round(performance.now() - start) + DebugBus.info('debug', `decrypt done ${mode}`, { len: typeof plain === 'string' ? plain.length : -1, ms }) if (mode === 'nip44') setPlain44(String(plain)) else setPlain04(String(plain)) + if (mode === 'nip44') setTDecrypt44(ms) + else setTDecrypt04(ms) } catch (e) { DebugBus.error('debug', `decrypt error ${mode}`, e instanceof Error ? e.message : String(e)) } @@ -88,7 +100,7 @@ const Debug: React.FC = () => {