Skip to content

Instantly share code, notes, and snippets.

@romanz
Created May 21, 2025 09:53
Show Gist options
  • Select an option

  • Save romanz/2630210f497b69d605cdb831fd057b98 to your computer and use it in GitHub Desktop.

Select an option

Save romanz/2630210f497b69d605cdb831fd057b98 to your computer and use it in GitHub Desktop.
use std::str::FromStr;
use bitcoin::{BlockHash, Txid};
use bitcoincore_rpc::{Auth, Client, RpcApi};
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
fn main() -> Result<()> {
let args: Vec<String> = std::env::args().skip(1).collect();
let auth = Auth::CookieFile(".cookie".into());
let rpc = Client::new("http://localhost:8332", auth)?;
let txid = Txid::from_str(&args[0])?;
let block_hash = BlockHash::from_str(&args[1])?;
let t = std::time::Instant::now();
let count = 1_000;
for _ in 0..count {
rpc.get_raw_transaction_hex(&txid, Some(&block_hash))?;
}
let dt = t.elapsed();
println!("iterations = {}", count);
println!("average RPC duration = {:?}", dt.div_f32(count as f32));
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment