mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
Show timing information
This commit is contained in:
parent
ced9876a01
commit
4b10613a0c
@ -4,6 +4,7 @@
|
|||||||
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
|
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
|
||||||
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
|
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
|
||||||
const { calculateFee, GasPrice } = require("@cosmjs/stargate");
|
const { calculateFee, GasPrice } = require("@cosmjs/stargate");
|
||||||
|
const { fromRfc3339, toRfc3339 } = require("@cosmjs/encoding");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
|
||||||
const endpoint = "http://localhost:26659";
|
const endpoint = "http://localhost:26659";
|
||||||
@ -29,6 +30,10 @@ async function main() {
|
|||||||
console.info(`Upload succeeded. Result: ${JSON.stringify(uploadResult)}`);
|
console.info(`Upload succeeded. Result: ${JSON.stringify(uploadResult)}`);
|
||||||
console.info("");
|
console.info("");
|
||||||
|
|
||||||
|
const startTime = Date.now();
|
||||||
|
const startHeight = await client.getHeight();
|
||||||
|
console.log(`Start time: ${toRfc3339(new Date(startTime))}, start height: ${startHeight}`);
|
||||||
|
|
||||||
const instantiateResult = await client.instantiate(
|
const instantiateResult = await client.instantiate(
|
||||||
alice.address0,
|
alice.address0,
|
||||||
uploadResult.codeId,
|
uploadResult.codeId,
|
||||||
@ -48,6 +53,22 @@ async function main() {
|
|||||||
instantiateResult,
|
instantiateResult,
|
||||||
)}`,
|
)}`,
|
||||||
);
|
);
|
||||||
|
const doneTime = Date.now();
|
||||||
|
const doneHeight = await client.getHeight();
|
||||||
|
console.log(`Done time: ${toRfc3339(new Date(doneTime))}, done height: ${doneHeight}`);
|
||||||
|
const runtime = (doneTime - startTime) / 1000;
|
||||||
|
console.info(`Instantiate call took ${runtime.toFixed(2)} seconds`);
|
||||||
|
|
||||||
|
for (let height2 = startHeight; height2 <= doneHeight; height2++) {
|
||||||
|
const height1 = height2 - 1;
|
||||||
|
const [block1, block2] = await Promise.all([client.getBlock(height1), client.getBlock(height2)]);
|
||||||
|
const date2 = fromRfc3339(block2.header.time);
|
||||||
|
const date1 = fromRfc3339(block1.header.time);
|
||||||
|
const blockTime = ((date2.getTime() - date1.getTime()) / 1000).toFixed(2);
|
||||||
|
console.info(
|
||||||
|
`Block ${height2} was created at ${block2.header.time}, ${blockTime} seconds after the previous block`,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main().then(
|
main().then(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user