Skip to content

Instantly share code, notes, and snippets.

@KMJ-007
Created November 17, 2025 08:53
Show Gist options
  • Select an option

  • Save KMJ-007/72f96dad4ee145da11e62a89996bd18e to your computer and use it in GitHub Desktop.

Select an option

Save KMJ-007/72f96dad4ee145da11e62a89996bd18e to your computer and use it in GitHub Desktop.
use std::time::Instant;
use aws_config::BehaviorVersion;
use aws_sdk_s3::Client;
use dotenvy::dotenv;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenv().ok();
let config = aws_config::defaults(BehaviorVersion::latest())
.region("auto")
.endpoint_url("https://t3.storage.dev")
.load()
.await;
let client = Client::new(&config);
let bucket = "test12";
let key = "rule-of-thumb-latency-numbers-letter.pdf";
println!("Testing GetObject latency...");
println!("Testing GetObject latency with multiple requests in same process...");
println!("Bucket: {}", bucket);
println!("Key: {}\n", key);
let start = Instant::now();
let resp = client
.get_object()
.bucket(bucket)
.key(key)
.send()
.await?;
let duration = start.elapsed();
// Get object metadata
let content_length = resp.content_length().unwrap_or(0);
let content_type = resp.content_type().unwrap_or("unknown");
println!("✓ Object retrieved successfully");
println!(" Content-Type: {}", content_type);
println!(" Content-Length: {} bytes ({:.2} KB)", content_length, content_length as f64 / 1024.0);
println!("\n⏱ GetObject latency: {:?}", duration);
println!("⏱ GetObject latency: {} ms", duration.as_millis());
// Test 5 requests in the same process
for i in 1..=5 {
let start = Instant::now();
let resp = client
.get_object()
.bucket(bucket)
.key(key)
.send()
.await?;
let duration = start.elapsed();
let content_length = resp.content_length().unwrap_or(0);
println!("Request #{}: {:>4} ms ({:.2} KB)",
i,
duration.as_millis(),
content_length as f64 / 1024.0
);
}
Ok(())
}
@KMJ-007
Copy link
Author

KMJ-007 commented Nov 17, 2025

use std::time::Instant;
use aws_config::BehaviorVersion;
use aws_sdk_s3::Client;
use dotenvy::dotenv;

#[tokio::main]
async fn main() -> Result<(), Box> {
dotenv().ok();

let config = aws_config::defaults(BehaviorVersion::latest())
    .region("auto")
    .endpoint_url("https://t3.storage.dev")
    .load()
    .await;

let client = Client::new(&config);

let bucket = "test12";
let key = "rule-of-thumb-latency-numbers-letter.pdf";

println!("Testing GetObject latency...");
println!("Bucket: {}", bucket);
println!("Key: {}\n", key);

let start = Instant::now();
let resp = client
    .get_object()
    .bucket(bucket)
    .key(key)
    .send()
    .await?;
let duration = start.elapsed();

// Get object metadata
let content_length = resp.content_length().unwrap_or(0);
let content_type = resp.content_type().unwrap_or("unknown");

println!("✓ Object retrieved successfully");
println!("  Content-Type: {}", content_type);
println!("  Content-Length: {} bytes ({:.2} KB)", content_length, content_length as f64 / 1024.0);
println!("\n⏱  GetObject latency: {:?}", duration);
println!("⏱  GetObject latency: {} ms", duration.as_millis());

Ok(())

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment