1
1
pub mod static_data;
2
2
3
+ use criterion:: Criterion ;
3
4
use static_data:: {
4
5
BURNTPIX_ADDRESS_ONE , BURNTPIX_ADDRESS_THREE , BURNTPIX_ADDRESS_TWO , BURNTPIX_BYTECODE_FOUR ,
5
6
BURNTPIX_BYTECODE_ONE , BURNTPIX_BYTECODE_THREE , BURNTPIX_BYTECODE_TWO , BURNTPIX_MAIN_ADDRESS ,
@@ -9,17 +10,15 @@ use static_data::{
9
10
use alloy_sol_types:: { sol, SolCall } ;
10
11
use database:: { CacheDB , BENCH_CALLER } ;
11
12
use revm:: {
12
- context_interface:: result:: { ExecutionResult , Output } ,
13
13
database_interface:: EmptyDB ,
14
14
primitives:: { hex, keccak256, Address , Bytes , TxKind , B256 , U256 } ,
15
15
state:: { AccountInfo , Bytecode } ,
16
16
Context , ExecuteEvm , MainBuilder , MainContext ,
17
17
} ;
18
18
19
- use std:: fs:: File ;
20
- use std:: { error:: Error , time:: Instant } ;
19
+ use std:: error:: Error ;
21
20
22
- use std:: { io :: Write , str:: FromStr } ;
21
+ use std:: str:: FromStr ;
23
22
24
23
sol ! {
25
24
#[ derive( Debug , PartialEq , Eq ) ]
28
27
}
29
28
}
30
29
31
- pub fn run ( ) {
30
+ pub fn run ( criterion : & mut Criterion ) {
32
31
let ( seed, iterations) = try_init_env_vars ( ) . expect ( "Failed to parse env vars" ) ;
33
32
34
33
let run_call_data = IBURNTPIX :: runCall { seed, iterations } . abi_encode ( ) ;
@@ -45,46 +44,52 @@ pub fn run() {
45
44
} )
46
45
. build_mainnet ( ) ;
47
46
48
- let started = Instant :: now ( ) ;
49
- let tx_result = evm. replay ( ) . unwrap ( ) . result ;
50
- let return_data = match tx_result {
51
- ExecutionResult :: Success {
52
- output, gas_used, ..
53
- } => {
54
- println ! ( "Gas used: {:?}" , gas_used) ;
55
- println ! ( "Time elapsed: {:?}" , started. elapsed( ) ) ;
56
- match output {
57
- Output :: Call ( value) => value,
58
- _ => unreachable ! ( "Unexpected output type" ) ,
59
- }
60
- }
61
- _ => unreachable ! ( "Execution failed: {:?}" , tx_result) ,
62
- } ;
63
-
64
- // Remove returndata offset and length from output
65
- let returndata_offset = 64 ;
66
- let data = & return_data[ returndata_offset..] ;
67
-
68
- // Remove trailing zeros
69
- let trimmed_data = data
70
- . split_at ( data. len ( ) - data. iter ( ) . rev ( ) . filter ( |& x| * x == 0 ) . count ( ) )
71
- . 0 ;
72
- let file_name = format ! ( "{}_{}" , seed, iterations) ;
73
-
74
- svg ( file_name, trimmed_data) . expect ( "Failed to store svg" ) ;
47
+ criterion. bench_function ( "burntpix" , |b| {
48
+ b. iter ( || {
49
+ let _ = evm. replay ( ) ;
50
+ } )
51
+ } ) ;
52
+
53
+ // Collects the data and uses it to generate the svg after running the benchmark
54
+ // let return_data = match tx_result {
55
+ // ExecutionResult::Success {
56
+ // output, gas_used, ..
57
+ // } => {
58
+ // println!("Gas used: {:?}", gas_used);
59
+ // match output {
60
+ // Output::Call(value) => value,
61
+ // _ => unreachable!("Unexpected output type"),
62
+ // }
63
+ // }
64
+ // _ => unreachable!("Execution failed: {:?}", tx_result),
65
+ // };
66
+
67
+ // // Remove returndata offset and length from output
68
+ // let returndata_offset = 64;
69
+ // let data = &return_data[returndata_offset..];
70
+
71
+ // // Remove trailing zeros
72
+ // let trimmed_data = data
73
+ // .split_at(data.len() - data.iter().rev().filter(|&x| *x == 0).count())
74
+ // .0;
75
+ // let file_name = format!("{}_{}", seed, iterations);
76
+
77
+ // svg(file_name, trimmed_data).expect("Failed to store svg");
78
+ // });
75
79
}
76
80
77
- fn svg ( filename : String , svg_data : & [ u8 ] ) -> Result < ( ) , Box < dyn Error > > {
78
- let current_dir = std:: env:: current_dir ( ) ?;
79
- let svg_dir = current_dir. join ( "burntpix" ) . join ( "svgs" ) ;
80
- std:: fs:: create_dir_all ( & svg_dir) ?;
81
+ // Actually generates the svg
82
+ // fn svg(filename: String, svg_data: &[u8]) -> Result<(), Box<dyn Error>> {
83
+ // let current_dir = std::env::current_dir()?;
84
+ // let svg_dir = current_dir.join("burntpix").join("svgs");
85
+ // std::fs::create_dir_all(&svg_dir)?;
81
86
82
- let file_path = svg_dir. join ( format ! ( "{}.svg" , filename) ) ;
83
- let mut file = File :: create ( file_path) ?;
84
- file. write_all ( svg_data) ?;
87
+ // let file_path = svg_dir.join(format!("{}.svg", filename));
88
+ // let mut file = File::create(file_path)?;
89
+ // file.write_all(svg_data)?;
85
90
86
- Ok ( ( ) )
87
- }
91
+ // Ok(())
92
+ // }
88
93
89
94
const DEFAULT_SEED : & str = "0" ;
90
95
const DEFAULT_ITERATIONS : & str = "0x7A120" ;
0 commit comments