I am trying to benchmark the time taken for a transaction to execute, can anybody advise me is there anyway I can record the time taken for smart contract transaction to complete?
-
I think you need to define "time taken for a transaction to execute" and "complete" more clearly (since the two, to me, quite different). For example, do you mean the amount of time from when the transaction is first submitted to the network to when it is first included in the blockchain? Or maybe you mean the amount of time it takes from when it enters the a node's txpool to when it is executed in preparation for inclusion into a block? Or only the amount of time it takes the EVM to run the code when the transaction is called? All require different measurement techniques.– lungjCommented Jul 17, 2018 at 14:47
-
I want to record the time difference between the when I issue it and the time it is recorded in blockchain– user9624803Commented Jul 17, 2018 at 14:49
1 Answer
On one of the major test nets, it's impossible to know the precise time that a block is generated because miners' clocks don't have to be perfectly accurate nor do the timestamps included in blocks need to be correct (they do need to be non-monotonic-decreasing from the last timestamp and less than 900s in the future). However, you can put an upper bound on the time when a block was generated by looking at the time you receive the associated block. Thus, you can note the time you submit the block and the time the including-block is received by monitoring the transaction post-broadcast.
There's probably a better way, but the simplest way to me is to write a program that connects to a node, submits the signed transaction, stores the time, and polls the node for when the transaction is included in a block and noting that time as well. It probably doesn't make sense to poll more than about 10 times a second since statistical variance in block mining times and network propagation delays are going to have a very large effect on the measured values.
-
+1 for mentioning about timestamps in block can not be 100% accurate. Commented Dec 10, 2019 at 7:35