use std::time::Instant;
use webpage_quality_analyzer::{analyze, analyze_with_profile};
#[tokio::test]
async fn test_large_document_performance() {
let large_html = format!(
r#"<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Large Performance Test Document</title>
<meta name="description" content="A large document for testing analyzer performance">
</head>
<body>
<header>
<nav>
<ul>
<li><a href="{}section1">Section 1</a></li>
<li><a href="{}section2">Section 2</a></li>
<li><a href="{}section3">Section 3</a></li>
</ul>
</nav>
</header>
<main>
<h1>Performance Test Document</h1>
<section id="section1">
<h2>Section 1: Content Analysis</h2>
<p>This is a comprehensive section containing substantial text content designed to test the analyzer text processing capabilities. The content includes multiple paragraphs, various HTML elements, and structured data to ensure thorough testing of all analysis metrics.</p>
<div class="content-block">
<h3>Subsection 1.1</h3>
<p>Additional content here with <strong>emphasized text</strong> and <em>italic formatting</em>. This paragraph contains sufficient text to contribute meaningfully to word count and readability metrics.</p>
<ul>
<li>List item one with descriptive content</li>
<li>List item two with more text</li>
<li>List item three containing even more detailed information</li>
<li>List item four with comprehensive details</li>
<li>List item five with extensive content</li>
</ul>
</div>
</section>
<section id="section2">
<h2>Section 2: Media and Links</h2>
<p>This section contains various media elements and external links to test the analyzer handling of multimedia content and link analysis.</p>
<img src="test-image1.jpg" alt="Test image for performance analysis">
<img src="test-image2.jpg" alt="Another test image with descriptive alt text">
<p>Here are some external links: <a href="https://example1.com">External Link 1</a>, <a href="https://example2.com">External Link 2</a>, and <a href="https://example3.com">External Link 3</a>.</p>
</section>
<section id="section3">
<h2>Section 3: Complex Structure</h2>
<table>
<caption>Performance Test Data</caption>
<thead>
<tr>
<th>Metric</th>
<th>Value</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td>Word Count</td>
<td>500+</td>
<td>Pass</td>
</tr>
<tr>
<td>Images</td>
<td>Multiple</td>
<td>Pass</td>
</tr>
<tr>
<td>Links</td>
<td>External</td>
<td>Pass</td>
</tr>
</tbody>
</table>
</section>
</main>
<footer>
<p>Footer content for document completeness.</p>
</footer>
</body>
</html>"#,
"#", "#", "#"
);
let start_time = Instant::now();
let report = analyze("https://example.com/large", Some(&large_html))
.await
.unwrap();
let duration = start_time.elapsed();
assert!(
duration.as_millis() < 1000,
"Analysis took too long: {:?}",
duration
);
assert!(report.score >= 0.0 && report.score <= 100.0);
assert!(report.metrics.html_analysis.content.word_count > 100);
assert!(report.metrics.html_analysis.structure.headings_count > 2);
println!("Large document analysis completed in {:?}", duration);
}
#[tokio::test]
async fn test_multiple_small_documents_performance() {
let small_html = r#"<!DOCTYPE html>
<html><head><title>Small</title></head>
<body><h1>Small Document</h1><p>Content here.</p></body></html>"#;
let start_time = Instant::now();
for i in 0..50 {
let url = format!("https://example.com/doc{}", i);
let _report = analyze(&url, Some(small_html)).await.unwrap();
}
let duration = start_time.elapsed();
assert!(
duration.as_millis() < 3000,
"50 analyses took too long: {:?}",
duration
);
println!("50 small document analyses completed in {:?}", duration);
}
#[tokio::test]
async fn test_different_profile_performance() {
let large_html = r#"<!DOCTYPE html>
<html><head><title>Performance Test</title></head>
<body>
<h1>Test Content</h1>
<p>This is test content for performance comparison between different scoring profiles.</p>
<p>Additional paragraph with more content to make the test more meaningful.</p>
<img src="test.jpg" alt="Test image">
<a href="https://example.com">External link</a>
</body>
</html>"#;
let url = "https://example.com/perf-test";
let start_time = Instant::now();
let _report1 = analyze(url, Some(&large_html)).await.unwrap();
let duration1 = start_time.elapsed();
let start_time = Instant::now();
let _report2 = analyze_with_profile(url, Some(&large_html), "content_article")
.await
.unwrap();
let duration2 = start_time.elapsed();
assert!(duration1.as_millis() < 1000);
assert!(duration2.as_millis() < 1000);
println!(
"Default profile: {:?}, Article profile: {:?}",
duration1, duration2
);
}
#[tokio::test]
async fn test_memory_usage_stability() {
let test_html = r#"<!DOCTYPE html>
<html><head><title>Memory Test</title></head>
<body>
<h1>Memory Test Document</h1>
<p>Content for memory stability testing.</p>
</body>
</html>"#;
for i in 0..20 {
let url = format!("https://example.com/memory-test-{}", i);
let report = analyze(&url, Some(test_html)).await.unwrap();
assert!(report.score >= 0.0 && report.score <= 100.0);
}
assert!(true);
}