Skip to content

Commit

Permalink
test(contracts): Add logs to calculate gas savings
Browse files Browse the repository at this point in the history
The cost of running benchmarks was determined by running them on the contracts at regenesis/0.4.0 (98e02cf/ PR #1148), then applied to the benchmarks here to calculate both absolute and relative amounts saed
  • Loading branch information
maurelian authored and smartcontracts committed Nov 10, 2021
1 parent 66bf56a commit 7aec095
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
27 changes: 25 additions & 2 deletions packages/contracts/test/contracts/L1/messaging/deposit.gas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,18 @@ describe('[GAS BENCHMARK] Depositing via the standard bridge', () => {
)

const receipt = await res.wait()
console.log(' - Gas used:', receipt.gasUsed.toNumber())
const gasUsed = receipt.gasUsed.toNumber()
const regenesis040Cost = 196_128
console.log(' - Gas used:', gasUsed)
console.log(
' - Absolute savings vs regenesis/0.4.0:',
regenesis040Cost - gasUsed
)
console.log(
' - Relative savings vs regenesis/0.4.0:',
(((regenesis040Cost - gasUsed) / regenesis040Cost) * 100).toFixed(2) +
'%'
)
// Sanity check that the message was enqueued.
expect(await CanonicalTransactionChain.getQueueLength()).to.equal(2)
})
Expand All @@ -163,7 +174,19 @@ describe('[GAS BENCHMARK] Depositing via the standard bridge', () => {
)

const receipt = await res.wait()
console.log(' - Gas used:', receipt.gasUsed.toNumber())
const gasUsed = receipt.gasUsed.toNumber()
const regenesis040Cost = 244_358
console.log(' - Gas used:', gasUsed)
console.log(
' - Absolute savings vs regenesis/0.4.0:',
regenesis040Cost - gasUsed
)
console.log(
' - Relative savings vs regenesis/0.4.0:',
(((regenesis040Cost - gasUsed) / regenesis040Cost) * 100).toFixed(2) +
'%'
)

// Sanity check that the message was enqueued.
expect(await CanonicalTransactionChain.getQueueLength()).to.equal(3)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ const appendSequencerBatch = async (
})
}

const printGasSavings = (gasUsed:number, regenesis040Cost:number):void => {
console.log(' - Gas used:', gasUsed)
console.log(
' - Absolute savings vs regenesis/0.4.0:',
regenesis040Cost - gasUsed
)
console.log(
' - Relative savings vs regenesis/0.4.0:',
(((regenesis040Cost - gasUsed) / regenesis040Cost) * 100).toFixed(2) +
'%'
)
}

describe('[GAS BENCHMARK] CanonicalTransactionChain', () => {
let sequencer: Signer
before(async () => {
Expand Down Expand Up @@ -151,7 +164,7 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain', () => {
const gasUsed = receipt.gasUsed.toNumber()

console.log('Benchmark complete.')
console.log('Gas used:', gasUsed)
printGasSavings(gasUsed, 1_616_390)

console.log('Fixed calldata cost:', fixedCalldataCost)
console.log(
Expand Down Expand Up @@ -199,7 +212,7 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain', () => {
const gasUsed = receipt.gasUsed.toNumber()

console.log('Benchmark complete.')
console.log('Gas used:', gasUsed)
printGasSavings(gasUsed, 1_787_052)

console.log('Fixed calldata cost:', fixedCalldataCost)
console.log(
Expand Down Expand Up @@ -257,7 +270,7 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain', () => {
const gasUsed = receipt.gasUsed.toNumber()

console.log('Benchmark complete.')
console.log('Gas used:', gasUsed)
printGasSavings(gasUsed, 2_099_387)

console.log('Fixed calldata cost:', fixedCalldataCost)
console.log(
Expand Down

0 comments on commit 7aec095

Please sign in to comment.