Using traceTransaction we can get the following data:

  gas: 104030,
  returnValue: "0000000000000000000000000000000000000000000000000000000000000001",
  structLogs: [{
      depth: 1,
      error: null,
      gas: 247189,
      gasCost: 3,
      memory: null,
      op: "PUSH1",
      pc: 0,
      stack: [],
      storage: {}
  }, {
      depth: 1,
      error: null,
      gas: 247186,
      gasCost: 3,
      memory: null,
      op: "PUSH1",
      pc: 2,
      stack: ["0000000000000000000000000000000000000000000000000000000000000060"],
      storage: {}
      depth: 1,
      error: null,
      gas: 165970,
      gasCost: 0,
      memory: ["0000000000000000000000000000000000000000000000000000000000000000", "0000000000000000000000000000000000000000000000000000000000000000", "00000000000000000000000000000000000000000000000000000000000000c0", "532e204d61747468657700000000000000000000000000000000000000000000", "456e676c69736800000000000000000000000000000000000000000000000000", "000000000000000000000000000000000000000000000000000000000000001c", "0000000000000000000000000000000000000000000000000000000000000001"],
      op: "RETURN",
      pc: 349,
      stack: ["00000000000000000000000000000000000000000000000000000000773b82a3", "0000000000000000000000000000000000000000000000000000000000000020", "00000000000000000000000000000000000000000000000000000000000000c0"],
      storage: {
        0000000000000000000000000000000000000000000000000000000000000000: "0000000000000000000000000000000000000000000000000000000000000001",
        290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563: "532e204d61747468657700000000000000000000000000000000000000000000",
        290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e564: "456e676c69736800000000000000000000000000000000000000000000000000",
        290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e565: "000000000000000000000000000000000000000000000000000000000000001c"

Is there some way to get the amount of time it takes for each opcode (op) to execute?

1 Answer 1


You can get every opcode executed time by changing source file, and rebuild, deploy to test. In instructions file, there are all opcode, what you should do is add log, it's so simple. As follows:

  1. Open local instructions source file, and the adding log you want to know executing time for every opcode. For instance, i added a log for opAdd instruction:

    func opAdd(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
        var startTime = time.Now().UnixNano();
        x, y := stack.pop(), stack.pop()
        stack.push(math.U256(x.Add(x, y)))
        fmt.Println("execute opAdd consume = ",(time.Now().UnixNano() - startTime))
        return nil, nil
  2. Rebuild. At first go to go-ethereum dir and execute make all command in terminal. If everything is ok, some cmd had been generated in dir of 'build/bin'.

  3. Run. executing command geth to go to console, and then check result of changing code. There are six opAdd ops for traceTransaction command. execute opAdd consume = 186 execute opAdd consume = 141 execute opAdd consume = 107 execute opAdd consume = 92 execute opAdd consume = 127 execute opAdd consume = 289

Hope it helps ~

  • this approach is awesome, for sure I'm going to do this, but just now when I tried make all I got the error: core/vm/instructions.go:37: undefined: time in time.Now core/vm/instructions.go:45: undefined: time in time.Now Aug 8, 2017 at 13:25
  • ok, nevermind- just had to import ("time"...) Aug 8, 2017 at 13:27
  • where will these opcodes render? can I access them through the console at geth attach ipc:/Users/s.matthew.english/Library/Ethereum/testnet/geth.ipc Aug 8, 2017 at 13:35
  • man, it seems I can't get this to show up in the console output thru attach Aug 8, 2017 at 13:39
  • Hi, if you had added log, cd go-ethereum dir, execute ./build/bin/geth datadir=/Users/s.matthew.english/Library/Ethereum/testnet console to go to console, and then call traceTransaction method. Aug 8, 2017 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.