2019-06-08 10:21:43 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#![feature(test)]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								extern crate test;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-18 10:28:51 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use solana_ledger::entry::{next_entry_mut, Entry, EntrySlice};
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-08 10:21:43 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								use solana_sdk::hash::{hash, Hash};
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-20 14:28:55 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use solana_sdk::signature::{Keypair, Signer};
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-08 10:21:43 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								use solana_sdk::system_transaction;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								use test::Bencher;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const NUM_HASHES: u64 = 400;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const NUM_ENTRIES: usize = 800;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[bench]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn bench_poh_verify_ticks(bencher: &mut Bencher) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-16 23:03:26 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    solana_logger::setup();
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-08 10:21:43 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let zero = Hash::default();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-16 23:03:26 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let start_hash = hash(&zero.as_ref());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let mut cur_hash = start_hash;
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-08 10:21:43 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let mut ticks: Vec<Entry> = Vec::with_capacity(NUM_ENTRIES);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for _ in 0..NUM_ENTRIES {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        ticks.push(next_entry_mut(&mut cur_hash, NUM_HASHES, vec![]));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bencher.iter(|| {
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-16 23:03:26 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        assert!(ticks.verify(&start_hash));
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-08 10:21:43 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[bench]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn bench_poh_verify_transaction_entries(bencher: &mut Bencher) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let zero = Hash::default();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-16 23:03:26 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let start_hash = hash(&zero.as_ref());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let mut cur_hash = start_hash;
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-08 10:21:43 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let keypair1 = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let pubkey1 = keypair1.pubkey();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let mut ticks: Vec<Entry> = Vec::with_capacity(NUM_ENTRIES);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for _ in 0..NUM_ENTRIES {
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-23 22:01:22 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        let tx = system_transaction::transfer(&keypair1, &pubkey1, 42, cur_hash);
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-08 10:21:43 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        ticks.push(next_entry_mut(&mut cur_hash, NUM_HASHES, vec![tx]));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bencher.iter(|| {
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-16 23:03:26 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        assert!(ticks.verify(&start_hash));
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-08 10:21:43 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |