mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	UserDefinedValueType: test to validate zero-cost-abstraction claim.
Seems that the optimizer can indeed make it a zero-cost-abstraction!
This commit is contained in:
		
							parent
							
								
									dea1b9ec79
								
							
						
					
					
						commit
						00bfed4d8b
					
				| @ -0,0 +1,37 @@ | ||||
| // a test to compare the cost between using user defined value types and elementary type. See the | ||||
| // test zero_cost_abstraction_userdefined.sol for a comparison. | ||||
| 
 | ||||
| pragma abicoder v2; | ||||
| 
 | ||||
| contract C { | ||||
|     int x; | ||||
|     function setX(int _x) external { | ||||
|         x = _x; | ||||
|     } | ||||
|     function getX() view external returns (int) { | ||||
|         return x; | ||||
|     } | ||||
|     function add(int a, int b) view external returns (int) { | ||||
|         return a + b; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| // ==== | ||||
| // compileViaYul: also | ||||
| // ---- | ||||
| // getX() -> 0 | ||||
| // gas irOptimized: 23353 | ||||
| // gas legacy: 23479 | ||||
| // gas legacyOptimized: 23311 | ||||
| // setX(int256): 5 -> | ||||
| // gas irOptimized: 43511 | ||||
| // gas legacy: 43724 | ||||
| // gas legacyOptimized: 43516 | ||||
| // getX() -> 5 | ||||
| // gas irOptimized: 23353 | ||||
| // gas legacy: 23479 | ||||
| // gas legacyOptimized: 23311 | ||||
| // add(int256,int256): 200, 99 -> 299 | ||||
| // gas irOptimized: 21794 | ||||
| // gas legacy: 22394 | ||||
| // gas legacyOptimized: 21813 | ||||
| @ -0,0 +1,38 @@ | ||||
| // a test to compare the cost between using user defined value types and elementary type. See the | ||||
| // test zero_cost_abstraction_elementary.sol for comparison. | ||||
| 
 | ||||
| pragma abicoder v2; | ||||
| 
 | ||||
| type MyInt is int; | ||||
| contract C { | ||||
|     int x; | ||||
|     function setX(MyInt _x) external { | ||||
|         x = MyInt.unwrap(_x); | ||||
|     } | ||||
|     function getX() view external returns (MyInt) { | ||||
|         return MyInt.wrap(x); | ||||
|     } | ||||
|     function add(MyInt a, MyInt b) pure external returns(MyInt) { | ||||
|         return MyInt.wrap(MyInt.unwrap(a) + MyInt.unwrap(b)); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| // ==== | ||||
| // compileViaYul: also | ||||
| // ---- | ||||
| // getX() -> 0 | ||||
| // gas irOptimized: 23353 | ||||
| // gas legacy: 23608 | ||||
| // gas legacyOptimized: 23311 | ||||
| // setX(int256): 5 -> | ||||
| // gas irOptimized: 43511 | ||||
| // gas legacy: 43724 | ||||
| // gas legacyOptimized: 43516 | ||||
| // getX() -> 5 | ||||
| // gas irOptimized: 23353 | ||||
| // gas legacy: 23608 | ||||
| // gas legacyOptimized: 23311 | ||||
| // add(int256,int256): 200, 99 -> 299 | ||||
| // gas irOptimized: 21794 | ||||
| // gas legacy: 22523 | ||||
| // gas legacyOptimized: 21813 | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user