This repo is a support for the answers to the following questions posted on StackExchange:
- What is the most gas efficient way to get the value of a bit in an unsigned integer?
- What are the pros and cons of emitting events vs return statements?
- Using assembly to store more values per word
And to the tweet:
Please don't take it as an example of good programming, it is just a very raw and fast way to test gas costs ;)
Start a local geth node in dev mode with
geth --http --dev
Then run
truffle compile
truffle test
Output will be something like this
Using network 'development'.
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
Contract: TestEvents
testReturnData 4235
✓ check costs 1
testReturnAndUseData 4247
✓ check costs 2
testEmitData 5681
✓ check costs 3
Contract: TestGasCosts
test1 188 188 188 188
✓ check costs 1 (1026ms)
test2 142 142 142 142
✓ check costs 2
test3 93 103 103 103
✓ check costs 3
test4 7 7 7 24
✓ check costs 4
test5 188 188 188 188
✓ check costs 5
Contract: TestLoops
testPlusPlusI 43068
✓ check costs 1
testIPlusPlus 43068
✓ check costs 2
Contract: TestPackingUint16
setPackedUint16 28901
✓ check costs 1 (1016ms)
testSetUint16 88443
✓ check costs 2
testPack 22134
✓ check costs 3
13 passing (4s)