webpage_quality_analyzer 1.0.2

High-performance webpage quality analyzer with 115 comprehensive metrics - Rust library with WASM, C++, and Python bindings
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
//! Performance and Optimization Examples
//!
//! This example demonstrates performance optimization techniques,
//! benchmarking, and best practices for high-throughput scenarios.

use webpage_quality_analyzer::{analyze, Analyzer};

#[path = "common/macros.rs"]
mod macros;
use std::collections::HashMap;
use std::time::{Duration, Instant};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    print_section!("", "Performance Optimization Examples");

    // Example 1: Performance Benchmarking
    println!("🏁 Example 1: Performance Benchmarking");
    println!("--------------------------------------");

    run_performance_benchmarks().await?;

    println!();

    // Example 2: Batch Processing Optimization
    println!("📦 Example 2: Batch Processing");
    println!("------------------------------");

    run_batch_processing_demo().await?;

    println!();

    // Example 3: Memory Usage Optimization
    println!("💾 Example 3: Memory Optimization");
    println!("---------------------------------");

    run_memory_optimization_demo().await?;

    println!();

    // Example 4: Configuration Optimization
    println!("⚙️  Example 4: Configuration Tuning");
    println!("-----------------------------------");

    run_configuration_optimization().await?;

    println!();

    // Example 5: Real-world Performance Tips
    println!("💡 Example 5: Real-world Optimization");
    println!("-------------------------------------");

    demonstrate_optimization_strategies().await?;

    println!();
    println!("🎉 Performance optimization examples completed!");
    println!();
    println!("🚀 Key Performance Takeaways:");
    println!("   • Reuse analyzer instances for better performance");
    println!("   • Disable unused features (NLP, link checking) for speed");
    println!("   • Use minimal reporting for high-throughput scenarios");
    println!("   • Optimize configuration for your specific use case");
    println!("   • Consider memory usage in long-running applications");

    Ok(())
}

async fn run_performance_benchmarks() -> Result<(), Box<dyn std::error::Error>> {
    println!("📊 Benchmarking different configuration approaches:");
    println!();

    let test_html = r#"
        <!DOCTYPE html>
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <title>Performance Test Article</title>
            <meta name="description" content="Testing performance with different analyzer configurations.">
        </head>
        <body>
            <article>
                <h1>Performance Testing Article</h1>
                
                <h2>Introduction</h2>
                <p>This article is designed to test the performance characteristics of different 
                analyzer configurations. It contains sufficient content to trigger all major 
                analysis components.</p>
                
                <h2>Content Analysis</h2>
                <p>The content analysis component examines text quality, readability, and structure. 
                This section provides enough text to ensure meaningful readability calculations and 
                content quality assessments.</p>
                
                <h3>Subsection Example</h3>
                <p>Subsections help demonstrate heading structure analysis and organization scoring. 
                Proper heading hierarchy is important for both SEO and accessibility.</p>
                
                <h2>Media and Links</h2>
                <p>This section contains various media elements and links to test different 
                analysis components:</p>
                
                <ul>
                    <li><a href="https://example.com/page1">External link one</a></li>
                    <li><a href="https://example.com/page2">External link two</a></li>
                    <li><a href="/internal-page">Internal link</a></li>
                </ul>
                
                <img src="test-image.jpg" alt="Test image for media analysis">
                
                <h2>Conclusion</h2>
                <p>This comprehensive test content ensures that all analysis components have 
                sufficient data to work with, providing realistic performance measurements.</p>
            </article>
        </body>
        </html>
    "#;

    let test_cases = vec![
        ("Minimal Config", create_minimal_analyzer().await?),
        ("Standard Config", create_standard_analyzer().await?),
        ("Full Features", create_full_featured_analyzer().await?),
        ("NLP Enabled", create_nlp_analyzer().await?),
        ("Link Checking", create_linkcheck_analyzer().await?),
    ];

    let mut results = HashMap::new();
    let iterations = 5;

    for (name, analyzer) in test_cases {
        println!("   Testing {}: ", name);

        let mut times = Vec::new();

        for i in 0..iterations {
            let start = Instant::now();

            match analyzer
                .run("https://performance-test.example.com", Some(test_html))
                .await
            {
                Ok(report) => {
                    let duration = start.elapsed();
                    times.push(duration);

                    if i == 0 {
                        print!("Score: {:.1} | ", report.score);
                    }
                }
                Err(e) => {
                    println!("❌ Failed: {}", e);
                    continue;
                }
            }
        }

        if !times.is_empty() {
            let avg_time = times.iter().sum::<Duration>() / times.len() as u32;
            let min_time = times.iter().min().unwrap();
            let max_time = times.iter().max().unwrap();

            println!(
                "Avg: {:.2?} (min: {:.2?}, max: {:.2?})",
                avg_time, min_time, max_time
            );
            results.insert(name, avg_time);
        }
    }

    // Performance comparison
    if let Some(baseline) = results.get("Minimal Config") {
        println!();
        println!("   📈 Performance Impact (vs Minimal Config):");

        let mut sorted_results: Vec<_> = results.iter().collect();
        sorted_results.sort_by_key(|(_, time)| *time);

        for (name, time) in sorted_results {
            if name != &"Minimal Config" {
                let overhead = time.as_millis() as f64 / baseline.as_millis() as f64;
                println!("     {}: {:.1}x slower ({:.2?})", name, overhead, time);
            } else {
                println!("     {} (baseline): {:.2?}", name, time);
            }
        }
    }

    Ok(())
}

async fn run_batch_processing_demo() -> Result<(), Box<dyn std::error::Error>> {
    println!("🔄 Batch processing optimization strategies:");
    println!();

    // Create test data
    let urls = (1..=20)
        .map(|i| format!("https://example{}.com", i))
        .collect::<Vec<_>>();
    let html_template = |id: usize| {
        format!(
            r#"
        <html>
        <head><title>Page {}</title></head>
        <body>
            <h1>Article {}</h1>
            <p>This is article number {} with some content for testing batch processing performance.</p>
            <h2>Section</h2>
            <p>Additional content to make the analysis more realistic and comprehensive.</p>
        </body>
        </html>
    "#,
            id, id, id
        )
    };

    // Strategy 1: Sequential processing
    println!("   📝 Strategy 1: Sequential Processing");
    let sequential_analyzer: Analyzer = Analyzer::builder()
        .with_profile_name("blog")?
        .add_report(false) // Minimal output for speed
        .build()?;

    let start = Instant::now();
    let mut sequential_results = Vec::new();

    for (i, url) in urls.iter().enumerate() {
        let html = html_template(i + 1);
        if let Ok(report) = sequential_analyzer.run(url, Some(&html)).await {
            sequential_results.push(report.score);
        }
    }

    let sequential_time = start.elapsed();
    println!(
        "     ✅ Processed {} pages in {:.2?}",
        sequential_results.len(),
        sequential_time
    );
    println!(
        "     Average score: {:.1}",
        sequential_results.iter().sum::<f32>() / sequential_results.len() as f32
    );

    // Strategy 2: Optimized analyzer reuse
    println!();
    println!("   ⚡ Strategy 2: Optimized Configuration");
    let optimized_analyzer: Analyzer = Analyzer::builder()
        .with_profile_name("blog")?
        .enable_linkcheck(false) // Disable for speed
        .enable_nlp(false) // Disable for speed
        .add_report(false) // Minimal output
        .build()?;

    let start = Instant::now();
    let mut optimized_results = Vec::new();

    for (i, url) in urls.iter().enumerate() {
        let html = html_template(i + 1);
        if let Ok(report) = optimized_analyzer.run(url, Some(&html)).await {
            optimized_results.push(report.score);
        }
    }

    let optimized_time = start.elapsed();
    println!(
        "     ✅ Processed {} pages in {:.2?}",
        optimized_results.len(),
        optimized_time
    );
    println!(
        "     Speed improvement: {:.1}x faster",
        sequential_time.as_millis() as f64 / optimized_time.as_millis() as f64
    );

    // Strategy 3: Concurrent processing (simulated)
    println!();
    println!("   🚀 Strategy 3: Batch with Concurrent-like Processing");
    let concurrent_analyzer: Analyzer = Analyzer::builder()
        .with_profile_name("blog")?
        .add_report(false)
        .build()?;

    let start = Instant::now();
    let mut concurrent_results = Vec::new();

    // Process in smaller batches to simulate concurrent processing benefits
    let batch_size = 5;
    for batch in urls.chunks(batch_size) {
        for (i, url) in batch.iter().enumerate() {
            let html = html_template(i + 1);
            if let Ok(report) = concurrent_analyzer.run(url, Some(&html)).await {
                concurrent_results.push(report.score);
            }
        }
        // Small delay to simulate batch processing coordination
        tokio::time::sleep(std::time::Duration::from_millis(1)).await;
    }

    let concurrent_time = start.elapsed();
    println!(
        "     ✅ Processed {} pages in {:.2?}",
        concurrent_results.len(),
        concurrent_time
    );

    // Recommendations
    println!();
    println!("   💡 Batch Processing Recommendations:");
    println!("     • Reuse analyzer instances instead of creating new ones");
    println!("     • Disable unused features (NLP, link checking) for speed");
    println!("     • Use add_report(false) for minimal memory footprint");
    println!("     • Process in batches to manage memory usage");
    println!("     • Consider async/await patterns for I/O bound operations");

    Ok(())
}

async fn run_memory_optimization_demo() -> Result<(), Box<dyn std::error::Error>> {
    println!("💾 Memory usage optimization strategies:");
    println!();

    let large_html = create_large_html_content();

    // Memory-heavy configuration
    println!("   📊 Memory Usage Comparison:");

    let memory_heavy_analyzer: Analyzer = Analyzer::builder()
        .with_profile_name("content_article")?
        .enable_nlp(true)
        .enable_linkcheck(true)
        .add_report(true) // Full detailed report
        .build()?;

    let start = Instant::now();
    match memory_heavy_analyzer
        .run("https://memory-test.example.com", Some(&large_html))
        .await
    {
        Ok(report) => {
            let processing_time = start.elapsed();
            println!("     Heavy Config: {:.2?} processing time", processing_time);
            println!("       Report size: ~{} KB", estimate_report_size(&report));
            println!(
                "       Metadata fields: {}",
                count_metadata_fields(&report.metadata)
            );
            println!(
                "       Document elements: {}",
                count_document_elements(&report.processed_document)
            );
        }
        Err(e) => println!("     ❌ Heavy config failed: {}", e),
    }

    // Memory-light configuration
    let memory_light_analyzer: Analyzer = Analyzer::builder()
        .with_profile_name("blog")?
        .enable_nlp(false)
        .enable_linkcheck(false)
        .add_report(false) // Minimal report
        .build()?;

    let start = Instant::now();
    match memory_light_analyzer
        .run("https://memory-test.example.com", Some(&large_html))
        .await
    {
        Ok(report) => {
            let processing_time = start.elapsed();
            println!("     Light Config: {:.2?} processing time", processing_time);
            println!("       Report size: ~{} KB", estimate_report_size(&report));
            println!(
                "       Minimal metadata: {}",
                report.metadata.title.len() > 0
            );
            println!(
                "       Minimal document: {}",
                report.processed_document.cleaned_text.len()
            );
        }
        Err(e) => println!("     ❌ Light config failed: {}", e),
    }

    println!();
    println!("   🔧 Memory Optimization Techniques:");
    println!("     1. Use add_report(false) to exclude detailed document data");
    println!("     2. Disable NLP processing if not needed");
    println!("     3. Disable link checking for faster processing");
    println!("     4. Choose appropriate profiles for your use case");
    println!("     5. Process large documents in smaller chunks if possible");
    println!("     6. Clear or reuse variables in long-running applications");

    Ok(())
}

async fn run_configuration_optimization() -> Result<(), Box<dyn std::error::Error>> {
    println!("⚙️  Configuration optimization for different use cases:");
    println!();

    let test_html = r#"
        <html>
        <head><title>Config Test</title></head>
        <body><h1>Test</h1><p>Configuration optimization test content.</p></body>
        </html>
    "#;

    let use_cases = vec![
        ("SEO Audit", create_seo_optimized_analyzer().await?),
        ("Content Review", create_content_optimized_analyzer().await?),
        ("Quick Check", create_speed_optimized_analyzer().await?),
        ("Comprehensive", create_comprehensive_analyzer().await?),
    ];

    for (use_case, analyzer) in use_cases {
        let start = Instant::now();

        match analyzer
            .run("https://config-test.example.com", Some(test_html))
            .await
        {
            Ok(report) => {
                let duration = start.elapsed();
                println!(
                    "   📋 {}: {:.1}/100 in {:.2?}",
                    use_case, report.score, duration
                );

                // Show relevant metrics based on use case
                match use_case {
                    "SEO Audit" => {
                        let seo = &report.metrics.html_analysis.seo;
                        println!(
                            "      SEO Focus: Title: {} chars, Meta: {}, OG: {}",
                            seo.title_len,
                            seo.meta_desc_len.is_some(),
                            seo.og_tags
                        );
                    }
                    "Content Review" => {
                        let content = &report.metrics.html_analysis.content;
                        println!(
                            "      Content Focus: {} words, {:.1} min read, {:.1}% density",
                            content.word_count,
                            content.reading_time_minutes,
                            content.content_density * 100.0
                        );
                    }
                    "Quick Check" => {
                        println!("      Speed Focus: Fast analysis with essential metrics only");
                    }
                    "Comprehensive" => {
                        println!(
                            "      Complete Analysis: All features enabled, detailed reporting"
                        );
                    }
                    _ => {}
                }
            }
            Err(e) => println!("{} failed: {}", use_case, e),
        }
    }

    println!();
    println!("   🎯 Configuration Guidelines:");
    println!("     • SEO Audit: Focus on metadata, structure, and technical aspects");
    println!("     • Content Review: Enable NLP, emphasize readability and quality");
    println!("     • Quick Check: Disable expensive features, minimal reporting");
    println!("     • Comprehensive: All features enabled for complete analysis");

    Ok(())
}

async fn demonstrate_optimization_strategies() -> Result<(), Box<dyn std::error::Error>> {
    println!("💡 Real-world optimization strategies:");
    println!();

    // Strategy 1: Analyzer Instance Reuse
    println!("   🔄 Strategy 1: Analyzer Instance Reuse");
    let reusable_analyzer: Analyzer = Analyzer::builder().with_profile_name("blog")?.build()?;

    let urls = vec![
        "https://blog1.example.com",
        "https://blog2.example.com",
        "https://blog3.example.com",
    ];

    let start = Instant::now();
    for url in &urls {
        let html = format!("<html><head><title>Blog</title></head><body><h1>Post</h1><p>Content for {}.</p></body></html>", url);
        let _ = reusable_analyzer.run(url, Some(&html)).await;
    }
    let reuse_time = start.elapsed();

    println!(
        "     ✅ Processed {} URLs with reused analyzer: {:.2?}",
        urls.len(),
        reuse_time
    );

    // Strategy 2: Feature Selection
    println!();
    println!("   ⚡ Strategy 2: Feature Selection Based on Needs");

    let feature_configs = vec![
        ("Basic", false, false),
        ("With NLP", true, false),
        ("With Links", false, true),
        ("Full Featured", true, true),
    ];

    for (name, nlp, links) in feature_configs {
        let analyzer: Analyzer = Analyzer::builder()
            .with_profile_name("content_article")?
            .enable_nlp(nlp)
            .enable_linkcheck(links)
            .build()?;

        let start = Instant::now();
        let html = "<html><head><title>Feature Test</title></head><body><h1>Test</h1><p>Testing feature selection.</p><a href='#'>Link</a></body></html>";

        if let Ok(_) = analyzer
            .run("https://feature-test.example.com", Some(html))
            .await
        {
            let duration = start.elapsed();
            println!("     {} config: {:.2?}", name, duration);
        }
    }

    // Strategy 3: Profile Selection
    println!();
    println!("   🎯 Strategy 3: Profile Selection Optimization");

    let content_types = vec![
        ("News Article", "news", "<html><head><title>Breaking News</title></head><body><h1>News</h1><p>Current events.</p></body></html>"),
        ("Blog Post", "blog", "<html><head><title>My Blog</title></head><body><h1>Blog</h1><p>Personal thoughts.</p></body></html>"),
        ("Product Page", "product", "<html><head><title>Amazing Product</title></head><body><h1>Product</h1><p>Buy now!</p></body></html>"),
    ];

    for (content_type, _profile, html) in content_types {
        let start = Instant::now();
        if let Ok(report) = analyze("https://example.com", Some(html)).await {
            let duration = start.elapsed();
            println!(
                "     {}: {:.1}/100 in {:.2?}",
                content_type, report.score, duration
            );
        }
    }

    println!();
    println!("   📈 Performance Best Practices:");
    println!("     1. 🔄 Reuse analyzer instances - avoid recreating");
    println!("     2. ⚡ Disable unused features for better performance");
    println!("     3. 🎯 Choose the right profile for your content type");
    println!("     4. 💾 Use minimal reporting for high-throughput scenarios");
    println!("     5. 📦 Process in batches to manage memory usage");
    println!("     6. 🔍 Profile your specific use case and optimize accordingly");

    Ok(())
}

// Helper functions for creating different analyzer configurations

async fn create_minimal_analyzer() -> Result<Analyzer, Box<dyn std::error::Error>> {
    Ok(Analyzer::builder()
        .enable_linkcheck(false)
        .enable_nlp(false)
        .add_report(false)
        .build()?)
}

async fn create_standard_analyzer() -> Result<Analyzer, Box<dyn std::error::Error>> {
    Ok(Analyzer::builder()
        .with_profile_name("content_article")?
        .build()?)
}

async fn create_full_featured_analyzer() -> Result<Analyzer, Box<dyn std::error::Error>> {
    Ok(Analyzer::builder()
        .with_profile_name("content_article")?
        .enable_linkcheck(true)
        .enable_nlp(true)
        .add_report(true)
        .build()?)
}

async fn create_nlp_analyzer() -> Result<Analyzer, Box<dyn std::error::Error>> {
    Ok(Analyzer::builder()
        .with_profile_name("content_article")?
        .enable_nlp(true)
        .enable_linkcheck(false)
        .build()?)
}

async fn create_linkcheck_analyzer() -> Result<Analyzer, Box<dyn std::error::Error>> {
    Ok(Analyzer::builder()
        .with_profile_name("content_article")?
        .enable_linkcheck(true)
        .linkcheck_sample(10)
        .enable_nlp(false)
        .build()?)
}

async fn create_seo_optimized_analyzer() -> Result<Analyzer, Box<dyn std::error::Error>> {
    Ok(Analyzer::builder()
        .with_profile_name("content_article")?
        .enable_linkcheck(true)
        .enable_nlp(false)
        .build()?)
}

async fn create_content_optimized_analyzer() -> Result<Analyzer, Box<dyn std::error::Error>> {
    Ok(Analyzer::builder()
        .with_profile_name("content_article")?
        .enable_nlp(true)
        .enable_linkcheck(false)
        .build()?)
}

async fn create_speed_optimized_analyzer() -> Result<Analyzer, Box<dyn std::error::Error>> {
    Ok(Analyzer::builder()
        .enable_linkcheck(false)
        .enable_nlp(false)
        .add_report(false)
        .build()?)
}

async fn create_comprehensive_analyzer() -> Result<Analyzer, Box<dyn std::error::Error>> {
    Ok(Analyzer::builder()
        .with_profile_name("content_article")?
        .enable_linkcheck(true)
        .linkcheck_sample(50)
        .enable_nlp(true)
        .add_report(true)
        .build()?)
}

// Helper functions for analysis

fn create_large_html_content() -> String {
    let mut html = String::from(
        r#"
        <!DOCTYPE html>
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <title>Large Content Test Document</title>
            <meta name="description" content="Large document for testing memory usage and performance.">
        </head>
        <body>
            <h1>Large Document Performance Test</h1>
    "#,
    );

    // Add many sections to create a large document
    for i in 1..=20 {
        html.push_str(&format!(r#"
            <h2>Section {}</h2>
            <p>This is section {} with substantial content to test memory usage and processing performance. 
            The content includes multiple sentences to ensure realistic text analysis and provide 
            sufficient data for all metrics calculations.</p>
            
            <h3>Subsection {}.1</h3>
            <p>Additional content in subsection {}.1 to create deeper heading structure and more 
            comprehensive text analysis opportunities.</p>
            
            <ul>
                <li><a href="https://example{}.com">Link {}</a></li>
                <li><a href="/internal-{}.html">Internal link {}</a></li>
            </ul>
            
            <img src="image{}.jpg" alt="Test image {} for media analysis">
        "#, i, i, i, i, i, i, i, i, i, i));
    }

    html.push_str("</body></html>");
    html
}

fn estimate_report_size(report: &webpage_quality_analyzer::PageQualityReport) -> usize {
    // Rough estimate of report size in KB
    let json_size = serde_json::to_string(report).unwrap_or_default().len();
    json_size / 1024
}

fn count_metadata_fields(metadata: &webpage_quality_analyzer::ExtractedMetadata) -> usize {
    let mut count = 0;
    if !metadata.title.is_empty() {
        count += 1;
    }
    if metadata.meta_description.is_some() {
        count += 1;
    }
    if metadata.author.is_some() {
        count += 1;
    }
    if metadata.language.is_some() {
        count += 1;
    }
    if metadata.charset.is_some() {
        count += 1;
    }
    count += metadata.og_tags.len();
    count += metadata.twitter_tags.len();
    count
}

fn count_document_elements(document: &webpage_quality_analyzer::ProcessedDocument) -> usize {
    document.headings.len() + document.links.len() + document.images.len() + document.forms.len()
}