limiteron 0.2.10

Unified flow control framework for Rust
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
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
// Copyright (c) 2026 Kirky.X
// SPDX-License-Identifier: MIT
//! 内存基准测试
//!
//! 测试各种组件的内存占用和内存稳定性,包括:
//! - 不同键数量内存占用
//! - 不同数据结构内存对比
//! - 持续运行内存稳定性
//! - 内存泄漏检测
//
// 此 benchmark 文件测试 deprecated 的 SlidingWindowLimiter 以维护历史性能基线。
#![allow(deprecated)]

use criterion::{BenchmarkId, Criterion, SamplingMode, black_box, criterion_group, criterion_main};
use dashmap::DashMap;
use limiteron::limiters::{
    FixedWindowLimiter, Limiter, ShardedSlidingWindowLimiter, SlidingWindowLimiter,
    TokenBucketLimiter,
};
use limiteron::matchers::{ConditionEvaluator, MatchCondition, RequestContext, Rule, RuleMatcher};
use limiteron::oxcache::Cache;
use limiteron::tokio::runtime::Runtime;
use std::alloc::{GlobalAlloc, System};
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::Duration;

// ============================================================================
// 内存分配跟踪器
// ============================================================================

/// 内存分配跟踪器
///
/// 用于跟踪内存分配情况,帮助检测内存泄漏
#[global_allocator]
static ALLOCATOR: TrackingAllocator = TrackingAllocator::new();

/// 跟踪内存分配的分配器
struct TrackingAllocator {
    inner: System,
    allocated: AtomicUsize,
}

impl TrackingAllocator {
    const fn new() -> Self {
        Self {
            inner: System,
            allocated: AtomicUsize::new(0),
        }
    }

    /// 获取已分配的总内存
    fn get_allocated(&self) -> usize {
        self.allocated.load(Ordering::Relaxed)
    }

    /// 重置分配计数
    fn reset(&self) {
        self.allocated.store(0, Ordering::Relaxed);
    }
}

unsafe impl GlobalAlloc for TrackingAllocator {
    unsafe fn alloc(&self, layout: std::alloc::Layout) -> *mut u8 {
        self.allocated.fetch_add(layout.size(), Ordering::Relaxed);
        unsafe { self.inner.alloc(layout) }
    }

    unsafe fn dealloc(&self, ptr: *mut u8, layout: std::alloc::Layout) {
        self.allocated.fetch_sub(layout.size(), Ordering::Relaxed);
        unsafe { self.inner.dealloc(ptr, layout) };
    }
}

/// 获取当前进程的内存使用量(近似值)
fn get_memory_usage() -> usize {
    ALLOCATOR.get_allocated()
}

// ============================================================================
// 内存占用测量
// ============================================================================

/// 基准测试:TokenBucket 内存占用
///
/// 测量不同键数量下的内存占用
fn bench_token_bucket_memory_usage(c: &mut Criterion) {
    let rt = Runtime::new().unwrap();

    let mut group = c.benchmark_group("token_bucket_memory_usage");
    group.sampling_mode(SamplingMode::Auto);

    // 测量不同数量限流器的内存占用
    for count in [100, 1_000, 10_000, 100_000].iter() {
        ALLOCATOR.reset();
        let before = get_memory_usage();

        let limiters: Vec<Arc<TokenBucketLimiter>> = (0..*count)
            .map(|_| Arc::new(TokenBucketLimiter::new(1000, 100)))
            .collect();

        let after = get_memory_usage();
        let used = after.saturating_sub(before);

        group.bench_with_input(BenchmarkId::new("instances", count), count, |b, _| {
            b.iter(|| {
                rt.block_on(async {
                    for limiter in &limiters {
                        let _ = black_box(limiter.allow(1).await);
                    }
                });
            });
        });

        println!(
            "TokenBucket: {} 个实例,内存占用: {} bytes ({:.2} MB), 平均每实例: {} bytes",
            count,
            used,
            used as f64 / 1024.0 / 1024.0,
            used / count
        );

        // 防止优化掉 limiters
        black_box(limiters);
    }

    group.finish();
}

/// 基准测试:SlidingWindow 内存占用
fn bench_sliding_window_memory_usage(c: &mut Criterion) {
    let rt = Runtime::new().unwrap();

    let mut group = c.benchmark_group("sliding_window_memory_usage");
    group.sampling_mode(SamplingMode::Auto);

    for count in [100, 1_000, 10_000, 100_000].iter() {
        ALLOCATOR.reset();
        let before = get_memory_usage();

        let limiters: Vec<Arc<SlidingWindowLimiter>> = (0..*count)
            .map(|_| Arc::new(SlidingWindowLimiter::new(Duration::from_secs(60), 1000)))
            .collect();

        let after = get_memory_usage();
        let used = after.saturating_sub(before);

        group.bench_with_input(BenchmarkId::new("instances", count), count, |b, _| {
            b.iter(|| {
                rt.block_on(async {
                    for limiter in &limiters {
                        let _ = black_box(limiter.allow(1).await);
                    }
                });
            });
        });

        println!(
            "SlidingWindow: {} 个实例,内存占用: {} bytes ({:.2} MB), 平均每实例: {} bytes",
            count,
            used,
            used as f64 / 1024.0 / 1024.0,
            used / count
        );

        black_box(limiters);
    }

    group.finish();
}

/// 基准测试:ShardedSlidingWindow 内存占用
fn bench_sharded_sliding_window_memory_usage(c: &mut Criterion) {
    let rt = Runtime::new().unwrap();

    let mut group = c.benchmark_group("sharded_sliding_window_memory_usage");
    group.sampling_mode(SamplingMode::Auto);

    for count in [100, 1_000, 10_000, 100_000].iter() {
        ALLOCATOR.reset();
        let before = get_memory_usage();

        let limiters: Vec<Arc<ShardedSlidingWindowLimiter>> = (0..*count)
            .map(|_| {
                Arc::new(ShardedSlidingWindowLimiter::new(
                    Duration::from_secs(60),
                    1000,
                ))
            })
            .collect();

        let after = get_memory_usage();
        let used = after.saturating_sub(before);

        group.bench_with_input(BenchmarkId::new("instances", count), count, |b, _| {
            b.iter(|| {
                rt.block_on(async {
                    for limiter in &limiters {
                        let _ = black_box(limiter.allow(1).await);
                    }
                });
            });
        });

        println!(
            "ShardedSlidingWindow: {} 个实例,内存占用: {} bytes ({:.2} MB), 平均每实例: {} bytes",
            count,
            used,
            used as f64 / 1024.0 / 1024.0,
            used / count
        );

        black_box(limiters);
    }

    group.finish();
}

/// 基准测试:FixedWindow 内存占用
fn bench_fixed_window_memory_usage(c: &mut Criterion) {
    let rt = Runtime::new().unwrap();

    let mut group = c.benchmark_group("fixed_window_memory_usage");
    group.sampling_mode(SamplingMode::Auto);

    for count in [100, 1_000, 10_000, 100_000].iter() {
        ALLOCATOR.reset();
        let before = get_memory_usage();

        let limiters: Vec<Arc<FixedWindowLimiter>> = (0..*count)
            .map(|_| Arc::new(FixedWindowLimiter::new(Duration::from_secs(60), 1000)))
            .collect();

        let after = get_memory_usage();
        let used = after.saturating_sub(before);

        group.bench_with_input(BenchmarkId::new("instances", count), count, |b, _| {
            b.iter(|| {
                rt.block_on(async {
                    for limiter in &limiters {
                        let _ = black_box(limiter.allow(1).await);
                    }
                });
            });
        });

        println!(
            "FixedWindow: {} 个实例,内存占用: {} bytes ({:.2} MB), 平均每实例: {} bytes",
            count,
            used,
            used as f64 / 1024.0 / 1024.0,
            used / count
        );

        black_box(limiters);
    }

    group.finish();
}

// ============================================================================
// 数据结构内存对比
// ============================================================================

/// 基准测试:DashMap 内存占用
fn bench_dashmap_memory_usage(c: &mut Criterion) {
    let mut group = c.benchmark_group("dashmap_memory_usage");
    group.sampling_mode(SamplingMode::Auto);

    for count in [1_000, 10_000, 100_000, 1_000_000].iter() {
        ALLOCATOR.reset();
        let before = get_memory_usage();

        let map: DashMap<String, u64> = DashMap::new();
        for i in 0..*count {
            map.insert(format!("key_{}", i), i as u64);
        }

        let after = get_memory_usage();
        let used = after.saturating_sub(before);

        println!(
            "DashMap: {} 个键值对,内存占用: {} bytes ({:.2} MB), 平均每条目: {} bytes",
            count,
            used,
            used as f64 / 1024.0 / 1024.0,
            used / count
        );

        group.bench_with_input(BenchmarkId::new("entries", count), count, |b, _| {
            b.iter(|| {
                let _ = black_box(map.get(&format!("key_{}", count / 2)));
            });
        });

        black_box(map);
    }

    group.finish();
}

/// 基准测试:Cache 内存占用
fn bench_cache_memory_usage(c: &mut Criterion) {
    let rt = Runtime::new().unwrap();

    let mut group = c.benchmark_group("cache_memory_usage");
    group.sampling_mode(SamplingMode::Auto);

    for count in [1_000, 10_000, 100_000].iter() {
        ALLOCATOR.reset();
        let before = get_memory_usage();

        let cache: Arc<Cache<String, String>> = Arc::new(
            rt.block_on(
                Cache::builder()
                    .capacity(*count as u64 * 2)
                    .ttl(Duration::from_secs(60))
                    .build(),
            )
            .unwrap(),
        );

        rt.block_on(async {
            for i in 0..*count {
                let _ = cache
                    .set(&format!("key_{}", i), &format!("value_{}", i))
                    .await;
            }
        });

        let after = get_memory_usage();
        let used = after.saturating_sub(before);

        println!(
            "Cache: {} 个条目,内存占用: {} bytes ({:.2} MB), 平均每条目: {} bytes",
            count,
            used,
            used as f64 / 1024.0 / 1024.0,
            used / count
        );

        let cache_clone = cache.clone();
        group.bench_with_input(BenchmarkId::new("entries", count), count, |b, _| {
            b.iter(|| {
                rt.block_on(async {
                    let _ = black_box(cache_clone.get(&format!("key_{}", count / 2)).await);
                });
            });
        });

        black_box(cache);
    }

    group.finish();
}

/// 基准测试:规则匹配器内存占用
fn bench_rule_matcher_memory_usage(c: &mut Criterion) {
    let mut group = c.benchmark_group("rule_matcher_memory_usage");
    group.sampling_mode(SamplingMode::Auto);

    for count in [10, 50, 100, 500, 1000].iter() {
        ALLOCATOR.reset();
        let before = get_memory_usage();

        let rules: Vec<Rule> = (0..*count)
            .map(|i| {
                let condition: Box<dyn ConditionEvaluator> =
                    Box::new(MatchCondition::User(vec![format!("user_{}", i)]));
                Rule {
                    id: format!("rule_{}", i),
                    name: format!("Test Rule {}", i),
                    priority: (100 - i as u16 % 100),
                    condition,
                    enabled: true,
                }
            })
            .collect();

        let matcher = RuleMatcher::with_dependencies(rules);

        let after = get_memory_usage();
        let used = after.saturating_sub(before);

        println!(
            "RuleMatcher: {} 条规则,内存占用: {} bytes ({:.2} KB), 平均每规则: {} bytes",
            count,
            used,
            used as f64 / 1024.0,
            used / count
        );

        let mut context = RequestContext::new();
        context.path = "/api/v5/users".to_string();
        context.method = "GET".to_string();

        group.bench_with_input(BenchmarkId::new("rules", count), count, |b, _| {
            b.iter(|| {
                let matched = matcher.match_all(&context);
                black_box(matched);
            });
        });

        black_box(matcher);
    }

    group.finish();
}

// ============================================================================
// 内存稳定性测试
// ============================================================================

/// 基准测试:持续运行内存稳定性
///
/// 测量在持续运行情况下内存是否稳定(不持续增长)
fn bench_memory_stability(c: &mut Criterion) {
    let rt = Runtime::new().unwrap();

    let mut group = c.benchmark_group("memory_stability");
    group.sampling_mode(SamplingMode::Auto);
    group.measurement_time(Duration::from_secs(30));

    // TokenBucket 稳定性
    let limiter = Arc::new(TokenBucketLimiter::new(1_000_000, 100_000));
    ALLOCATOR.reset();
    let initial_memory = get_memory_usage();

    group.bench_function("token_bucket_stability", |b| {
        let limiter = limiter.clone();
        b.iter(|| {
            rt.block_on(async {
                for _ in 0..1000 {
                    let _ = black_box(limiter.allow(1).await);
                }
            });
        });
    });

    let final_memory = get_memory_usage();
    let memory_growth = final_memory.saturating_sub(initial_memory);
    println!(
        "TokenBucket 内存增长: {} bytes ({:.2} KB)",
        memory_growth,
        memory_growth as f64 / 1024.0
    );

    // SlidingWindow 稳定性
    let limiter = Arc::new(SlidingWindowLimiter::new(
        Duration::from_secs(60),
        1_000_000,
    ));
    ALLOCATOR.reset();
    let initial_memory = get_memory_usage();

    group.bench_function("sliding_window_stability", |b| {
        let limiter = limiter.clone();
        b.iter(|| {
            rt.block_on(async {
                for _ in 0..1000 {
                    let _ = black_box(limiter.allow(1).await);
                }
            });
        });
    });

    let final_memory = get_memory_usage();
    let memory_growth = final_memory.saturating_sub(initial_memory);
    println!(
        "SlidingWindow 内存增长: {} bytes ({:.2} KB)",
        memory_growth,
        memory_growth as f64 / 1024.0
    );

    // ShardedSlidingWindow 稳定性
    let limiter = Arc::new(ShardedSlidingWindowLimiter::new(
        Duration::from_secs(60),
        1_000_000,
    ));
    ALLOCATOR.reset();
    let initial_memory = get_memory_usage();

    group.bench_function("sharded_stability", |b| {
        let limiter = limiter.clone();
        b.iter(|| {
            rt.block_on(async {
                for _ in 0..1000 {
                    let _ = black_box(limiter.allow(1).await);
                }
            });
        });
    });

    let final_memory = get_memory_usage();
    let memory_growth = final_memory.saturating_sub(initial_memory);
    println!(
        "ShardedSlidingWindow 内存增长: {} bytes ({:.2} KB)",
        memory_growth,
        memory_growth as f64 / 1024.0
    );

    group.finish();
}

/// 基准测试:高负载内存稳定性
///
/// 测量在高负载情况下的内存稳定性
fn bench_high_load_memory_stability(c: &mut Criterion) {
    let rt = Runtime::new().unwrap();

    let mut group = c.benchmark_group("high_load_memory_stability");
    group.sampling_mode(SamplingMode::Auto);
    group.measurement_time(Duration::from_secs(30));

    // 创建大量请求模拟高负载
    let limiter = Arc::new(ShardedSlidingWindowLimiter::new(
        Duration::from_secs(60),
        10_000_000,
    ));

    ALLOCATOR.reset();
    let initial_memory = get_memory_usage();

    // 预热
    rt.block_on(async {
        for _ in 0..100_000 {
            let _ = limiter.allow(1).await;
        }
    });

    let after_warmup = get_memory_usage();
    println!(
        "预热后内存: {} bytes ({:.2} MB)",
        after_warmup,
        after_warmup as f64 / 1024.0 / 1024.0
    );

    group.bench_function("high_load_stability", |b| {
        let limiter = limiter.clone();
        b.iter(|| {
            rt.block_on(async {
                for _ in 0..10_000 {
                    let _ = black_box(limiter.allow(1).await);
                }
            });
        });
    });

    let final_memory = get_memory_usage();
    let total_growth = final_memory.saturating_sub(initial_memory);
    println!(
        "高负载测试总内存增长: {} bytes ({:.2} MB)",
        total_growth,
        total_growth as f64 / 1024.0 / 1024.0
    );

    group.finish();
}

// ============================================================================
// 内存泄漏检测
// ============================================================================

/// 基准测试:内存泄漏检测
///
/// 通过多次迭代检测是否存在内存泄漏
fn bench_memory_leak_detection(c: &mut Criterion) {
    let rt = Runtime::new().unwrap();

    let mut group = c.benchmark_group("memory_leak_detection");
    group.sampling_mode(SamplingMode::Auto);

    // 测试创建和销毁限流器
    ALLOCATOR.reset();
    let mut memory_samples = Vec::new();

    for iteration in 0..10 {
        let before = get_memory_usage();

        // 创建并使用限流器
        for _ in 0..1000 {
            let limiter = TokenBucketLimiter::new(1000, 100);
            rt.block_on(async {
                let _ = limiter.allow(1).await;
            });
        }

        let after = get_memory_usage();
        let used = after.saturating_sub(before);
        memory_samples.push(used);

        println!("迭代 {}: 内存使用 {} bytes", iteration, used);
    }

    // 分析内存趋势
    if memory_samples.len() >= 3 {
        let first_third = &memory_samples[..memory_samples.len() / 3];
        let last_third = &memory_samples[memory_samples.len() * 2 / 3..];

        let avg_first: usize = first_third.iter().sum::<usize>() / first_third.len();
        let avg_last: usize = last_third.iter().sum::<usize>() / last_third.len();

        let growth_rate = (avg_last as f64 - avg_first as f64) / avg_first as f64;

        println!(
            "内存增长趋势: 前1/3平均 {} bytes, 后1/3平均 {} bytes, 增长率 {:.2}%",
            avg_first,
            avg_last,
            growth_rate * 100.0
        );

        if growth_rate > 0.1 {
            println!("警告: 检测到可能的内存泄漏 (增长率 > 10%)");
        }
    }

    group.finish();
}

/// 基准测试:缓存内存泄漏检测
fn bench_cache_memory_leak_detection(c: &mut Criterion) {
    let rt = Runtime::new().unwrap();

    let mut group = c.benchmark_group("cache_memory_leak_detection");
    group.sampling_mode(SamplingMode::Auto);

    let cache: Arc<Cache<String, String>> = Arc::new(
        rt.block_on(
            Cache::builder()
                .capacity(100_000)
                .ttl(Duration::from_secs(60))
                .build(),
        )
        .unwrap(),
    );

    ALLOCATOR.reset();
    let mut memory_samples = Vec::new();

    for iteration in 0..10 {
        let before = get_memory_usage();

        // 写入和读取缓存
        rt.block_on(async {
            for i in 0..10_000 {
                let _ = cache
                    .set(&format!("key_{}", i), &format!("value_{}", i))
                    .await;
                let _ = cache.get(&format!("key_{}", i)).await;
            }
        });

        let after = get_memory_usage();
        let used = after.saturating_sub(before);
        memory_samples.push(used);

        println!("缓存迭代 {}: 内存使用 {} bytes", iteration, used);
    }

    // 分析内存趋势
    if memory_samples.len() >= 3 {
        let first = memory_samples[0];
        let last = *memory_samples.last().unwrap();
        let growth = last.saturating_sub(first);

        println!(
            "缓存测试: 初始 {} bytes, 最终 {} bytes, 增长 {} bytes",
            first, last, growth
        );

        if growth > 1_000_000 {
            println!("警告: 缓存内存增长超过 1MB,可能存在内存泄漏");
        }
    }

    group.finish();
}

// ============================================================================
// 并发内存测试
// ============================================================================

/// 基准测试:并发内存使用
fn bench_concurrent_memory_usage(c: &mut Criterion) {
    let rt = Runtime::new().unwrap();

    let mut group = c.benchmark_group("concurrent_memory_usage");
    group.sampling_mode(SamplingMode::Auto);

    let limiter = Arc::new(ShardedSlidingWindowLimiter::new(
        Duration::from_secs(60),
        10_000_000,
    ));

    for concurrency in [1, 4, 8, 16, 32].iter() {
        ALLOCATOR.reset();
        let before = get_memory_usage();

        group.bench_with_input(
            BenchmarkId::new("concurrency", concurrency),
            concurrency,
            |b, _| {
                let limiter = limiter.clone();
                b.iter(|| {
                    rt.block_on(async {
                        let mut handles = vec![];
                        for _ in 0..*concurrency {
                            let limiter = limiter.clone();
                            handles.push(async move {
                                for _ in 0..1000 {
                                    let _ = limiter.allow(1).await;
                                }
                            });
                        }
                        for handle in handles {
                            handle.await;
                        }
                    });
                });
            },
        );

        let after = get_memory_usage();
        let used = after.saturating_sub(before);

        println!(
            "并发 {} 线程: 内存使用 {} bytes ({:.2} MB)",
            concurrency,
            used,
            used as f64 / 1024.0 / 1024.0
        );
    }

    group.finish();
}

// ============================================================================
// 基准测试组配置
// ============================================================================

/// 配置 Criterion
fn configure_criterion() -> Criterion {
    Criterion::default()
        .confidence_level(0.95)
        .significance_level(0.05)
        .sample_size(50) // 减少样本数以加快内存测试
        .with_plots()
}

criterion_group! {
    name = memory_usage;
    config = configure_criterion();
    targets =
        bench_token_bucket_memory_usage,
        bench_sliding_window_memory_usage,
        bench_sharded_sliding_window_memory_usage,
        bench_fixed_window_memory_usage
}

criterion_group! {
    name = data_structure_memory;
    config = configure_criterion();
    targets =
        bench_dashmap_memory_usage,
        bench_cache_memory_usage,
        bench_rule_matcher_memory_usage
}

criterion_group! {
    name = memory_stability;
    config = configure_criterion();
    targets =
        bench_memory_stability,
        bench_high_load_memory_stability
}

criterion_group! {
    name = memory_leak;
    config = configure_criterion();
    targets =
        bench_memory_leak_detection,
        bench_cache_memory_leak_detection
}

criterion_group! {
    name = concurrent_memory;
    config = configure_criterion();
    targets =
        bench_concurrent_memory_usage
}

criterion_main!(
    memory_usage,
    data_structure_memory,
    memory_stability,
    memory_leak,
    concurrent_memory
);