File tree 2 files changed +31
-9
lines changed 2 files changed +31
-9
lines changed Original file line number Diff line number Diff line change @@ -253,13 +253,6 @@ impl GasMetering {
253
253
254
254
/// Stop the gas recording.
255
255
pub fn stop ( & mut self ) {
256
- println ! ( "gas records: {:?}" , self . gas_records) ;
257
-
258
- // self.gas_records.iter_mut().for_each(|record| {
259
- // record.gas_used.saturating_add(self.recorded_frames.iter().sum::<u64>());
260
- // });
261
-
262
- // reduce sum of gas frames to a single value
263
256
self . recording = false ;
264
257
}
265
258
Original file line number Diff line number Diff line change @@ -3,9 +3,11 @@ pragma solidity 0.8.18;
3
3
4
4
import "ds-test/test.sol " ;
5
5
import "cheats/Vm.sol " ;
6
+ import "../logs/console.sol " ;
6
7
7
8
contract GasSnapshotTest is DSTest {
8
9
uint256 public slot0;
10
+ uint256 public cachedGas = 0 ;
9
11
10
12
Vm constant vm = Vm (HEVM_ADDRESS);
11
13
@@ -48,11 +50,38 @@ contract GasSnapshotTest is DSTest {
48
50
function testGasComplex () public {
49
51
TargetB target = new TargetB ();
50
52
53
+ // Warm up the cache.
54
+ target.update (1 );
55
+
56
+ // Start a cheatcode snapshot.
51
57
vm.startSnapshotGas ("testAssertGasComplexA " );
52
58
53
- target.update (1 );
59
+ target.update (2 );
54
60
55
- vm.stopSnapshotGas ();
61
+ uint256 gasA = vm.stopSnapshotGas ();
62
+ console.log ("gas native A " , gasA);
63
+
64
+ // Start a comparitive Solidity snapshot.
65
+
66
+ // Warm up the cache.
67
+ cachedGas = 1 ;
68
+
69
+ // Start the Solidity snapshot.
70
+ cachedGas = gasleft ();
71
+
72
+ target.update (3 );
73
+
74
+ uint256 gasAfter = gasleft ();
75
+
76
+ console.log ("gas solidity " , cachedGas - gasAfter - 100 );
77
+
78
+ // Start a cheatcode snapshot.
79
+ vm.startSnapshotGas ("testAssertGasComplexB " );
80
+
81
+ target.update (4 );
82
+
83
+ uint256 gasB = vm.stopSnapshotGas ();
84
+ console.log ("gas native B " , gasB);
56
85
}
57
86
58
87
// Writes to `GasSnapshotTest` group with custom names.
You can’t perform that action at this time.
0 commit comments