Merge commit 'd803bfe2b1fe7f5e219e50ac20d6801a0a58ac75' as 'vendor/ruvector'
This commit is contained in:
180
vendor/ruvector/examples/exo-ai-2025/benches/README.md
vendored
Normal file
180
vendor/ruvector/examples/exo-ai-2025/benches/README.md
vendored
Normal file
@@ -0,0 +1,180 @@
|
||||
# EXO-AI 2025 Performance Benchmarks
|
||||
|
||||
This directory contains comprehensive criterion-based benchmarks for the EXO-AI cognitive substrate.
|
||||
|
||||
## Benchmark Suites
|
||||
|
||||
### 1. Manifold Benchmarks (`manifold_bench.rs`)
|
||||
|
||||
**Purpose**: Measure geometric manifold operations for concept embedding and retrieval.
|
||||
|
||||
**Benchmarks**:
|
||||
- `manifold_retrieval`: Query performance across different concept counts (100-5000)
|
||||
- `manifold_deformation`: Batch embedding throughput (10-500 concepts)
|
||||
- `manifold_local_adaptation`: Adaptive learning speed
|
||||
- `manifold_curvature`: Geometric computation performance
|
||||
|
||||
**Expected Baselines** (on modern CPU):
|
||||
- Retrieval @ 1000 concepts: < 100μs
|
||||
- Deformation batch (100): < 1ms
|
||||
- Local adaptation: < 50μs
|
||||
- Curvature computation: < 10μs
|
||||
|
||||
### 2. Hypergraph Benchmarks (`hypergraph_bench.rs`)
|
||||
|
||||
**Purpose**: Measure higher-order relational reasoning performance.
|
||||
|
||||
**Benchmarks**:
|
||||
- `hypergraph_edge_creation`: Hyperedge creation rate (2-50 nodes per edge)
|
||||
- `hypergraph_query`: Incident edge queries (100-5000 edges)
|
||||
- `hypergraph_pattern_match`: Pattern matching latency
|
||||
- `hypergraph_subgraph_extraction`: Subgraph extraction speed
|
||||
|
||||
**Expected Baselines**:
|
||||
- Edge creation (5 nodes): < 5μs
|
||||
- Query @ 1000 edges: < 50μs
|
||||
- Pattern matching: < 100μs
|
||||
- Subgraph extraction (depth 2): < 200μs
|
||||
|
||||
### 3. Temporal Benchmarks (`temporal_bench.rs`)
|
||||
|
||||
**Purpose**: Measure temporal coordination and causal reasoning.
|
||||
|
||||
**Benchmarks**:
|
||||
- `temporal_causal_query`: Causal ancestor queries (100-5000 events)
|
||||
- `temporal_consolidation`: Memory consolidation time (100-1000 events)
|
||||
- `temporal_range_query`: Time range query performance
|
||||
- `temporal_causal_path`: Causal path finding
|
||||
- `temporal_event_pruning`: Old event pruning speed
|
||||
|
||||
**Expected Baselines**:
|
||||
- Causal query @ 1000 events: < 100μs
|
||||
- Consolidation (500 events): < 5ms
|
||||
- Range query: < 200μs
|
||||
- Path finding (100 hops): < 500μs
|
||||
- Pruning (5000 events): < 2ms
|
||||
|
||||
### 4. Federation Benchmarks (`federation_bench.rs`)
|
||||
|
||||
**Purpose**: Measure distributed coordination and consensus.
|
||||
|
||||
**Benchmarks**:
|
||||
- `federation_crdt_merge`: CRDT operation throughput (10-500 ops)
|
||||
- `federation_consensus`: Consensus round latency (3-10 nodes)
|
||||
- `federation_state_sync`: State synchronization time
|
||||
- `federation_crypto_sign`: Cryptographic signing speed
|
||||
- `federation_crypto_verify`: Signature verification speed
|
||||
- `federation_gossip`: Gossip propagation performance (5-50 nodes)
|
||||
|
||||
**Expected Baselines** (async operations):
|
||||
- CRDT merge (100 ops): < 5ms
|
||||
- Consensus (5 nodes): < 50ms
|
||||
- State sync (100 items): < 10ms
|
||||
- Sign operation: < 100μs
|
||||
- Verify operation: < 150μs
|
||||
- Gossip (10 nodes): < 20ms
|
||||
|
||||
## Running Benchmarks
|
||||
|
||||
### Run All Benchmarks
|
||||
```bash
|
||||
cargo bench
|
||||
```
|
||||
|
||||
### Run Specific Suite
|
||||
```bash
|
||||
cargo bench --bench manifold_bench
|
||||
cargo bench --bench hypergraph_bench
|
||||
cargo bench --bench temporal_bench
|
||||
cargo bench --bench federation_bench
|
||||
```
|
||||
|
||||
### Run Specific Benchmark
|
||||
```bash
|
||||
cargo bench --bench manifold_bench -- manifold_retrieval
|
||||
cargo bench --bench temporal_bench -- causal_query
|
||||
```
|
||||
|
||||
### Generate Detailed Reports
|
||||
```bash
|
||||
cargo bench -- --save-baseline initial
|
||||
cargo bench -- --baseline initial
|
||||
```
|
||||
|
||||
## Benchmark Configuration
|
||||
|
||||
Criterion is configured with:
|
||||
- HTML reports enabled (in `target/criterion/`)
|
||||
- Statistical significance testing
|
||||
- Outlier detection
|
||||
- Performance regression detection
|
||||
|
||||
## Performance Targets
|
||||
|
||||
### Cognitive Operations (Target: Real-time)
|
||||
- Single concept retrieval: < 1ms
|
||||
- Hypergraph query: < 100μs
|
||||
- Causal inference: < 500μs
|
||||
|
||||
### Batch Operations (Target: High throughput)
|
||||
- Embedding batch (100): < 5ms
|
||||
- CRDT merges (100): < 10ms
|
||||
- Pattern matching: < 1ms
|
||||
|
||||
### Distributed Operations (Target: Low latency)
|
||||
- Consensus round (5 nodes): < 100ms
|
||||
- State synchronization: < 50ms
|
||||
- Gossip propagation: < 20ms/hop
|
||||
|
||||
## Analyzing Results
|
||||
|
||||
1. **HTML Reports**: Open `target/criterion/report/index.html`
|
||||
2. **Statistical Analysis**: Check for confidence intervals
|
||||
3. **Regression Detection**: Compare against baselines
|
||||
4. **Scaling Analysis**: Review performance across different input sizes
|
||||
|
||||
## Optimization Guidelines
|
||||
|
||||
### When to Optimize
|
||||
- Operations exceeding 2x baseline targets
|
||||
- Significant performance regressions
|
||||
- Poor scaling characteristics
|
||||
- High variance in measurements
|
||||
|
||||
### Optimization Priorities
|
||||
1. **Critical Path**: Manifold retrieval, hypergraph queries
|
||||
2. **Throughput**: Batch operations, CRDT merges
|
||||
3. **Latency**: Consensus, synchronization
|
||||
4. **Scalability**: Large-scale operations
|
||||
|
||||
## Continuous Benchmarking
|
||||
|
||||
Run benchmarks:
|
||||
- Before major commits
|
||||
- After performance optimizations
|
||||
- During release candidates
|
||||
- Weekly baseline updates
|
||||
|
||||
## Hardware Considerations
|
||||
|
||||
Benchmarks are hardware-dependent. For consistent results:
|
||||
- Use dedicated benchmark machines
|
||||
- Disable CPU frequency scaling
|
||||
- Close unnecessary applications
|
||||
- Run multiple iterations
|
||||
- Use `--baseline` for comparisons
|
||||
|
||||
## Contributing
|
||||
|
||||
When adding new benchmarks:
|
||||
1. Follow existing naming conventions
|
||||
2. Include multiple input sizes
|
||||
3. Document expected baselines
|
||||
4. Add to this README
|
||||
5. Verify statistical significance
|
||||
|
||||
---
|
||||
|
||||
**Last Updated**: 2025-11-29
|
||||
**Benchmark Suite Version**: 0.1.0
|
||||
**Criterion Version**: 0.5
|
||||
79
vendor/ruvector/examples/exo-ai-2025/benches/federation_bench.rs
vendored
Normal file
79
vendor/ruvector/examples/exo-ai-2025/benches/federation_bench.rs
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion, BenchmarkId};
|
||||
use exo_federation::{FederatedMesh, SubstrateInstance, FederationScope, StateUpdate, PeerAddress};
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
fn create_test_runtime() -> Runtime {
|
||||
tokio::runtime::Builder::new_multi_thread()
|
||||
.worker_threads(4)
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn create_test_mesh() -> FederatedMesh {
|
||||
let substrate = SubstrateInstance {};
|
||||
FederatedMesh::new(substrate).unwrap()
|
||||
}
|
||||
|
||||
fn benchmark_local_query(c: &mut Criterion) {
|
||||
let rt = create_test_runtime();
|
||||
|
||||
c.bench_function("federation_local_query", |b| {
|
||||
let mesh = create_test_mesh();
|
||||
let query = vec![1, 2, 3, 4, 5];
|
||||
|
||||
b.iter(|| {
|
||||
rt.block_on(async {
|
||||
mesh.federated_query(
|
||||
black_box(query.clone()),
|
||||
black_box(FederationScope::Local),
|
||||
).await
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn benchmark_consensus(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("federation_consensus");
|
||||
let rt = create_test_runtime();
|
||||
|
||||
for num_peers in [3, 5, 7, 10].iter() {
|
||||
group.bench_with_input(
|
||||
BenchmarkId::from_parameter(num_peers),
|
||||
num_peers,
|
||||
|b, &_peers| {
|
||||
let mesh = create_test_mesh();
|
||||
|
||||
b.iter(|| {
|
||||
rt.block_on(async {
|
||||
let update = StateUpdate {
|
||||
update_id: "test_update".to_string(),
|
||||
data: vec![1, 2, 3, 4, 5],
|
||||
timestamp: 12345,
|
||||
};
|
||||
mesh.byzantine_commit(black_box(update)).await
|
||||
})
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
group.finish();
|
||||
}
|
||||
|
||||
fn benchmark_mesh_creation(c: &mut Criterion) {
|
||||
c.bench_function("federation_mesh_creation", |b| {
|
||||
b.iter(|| {
|
||||
let substrate = SubstrateInstance {};
|
||||
FederatedMesh::new(black_box(substrate))
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(
|
||||
benches,
|
||||
benchmark_local_query,
|
||||
benchmark_consensus,
|
||||
benchmark_mesh_creation
|
||||
);
|
||||
criterion_main!(benches);
|
||||
111
vendor/ruvector/examples/exo-ai-2025/benches/hypergraph_bench.rs
vendored
Normal file
111
vendor/ruvector/examples/exo-ai-2025/benches/hypergraph_bench.rs
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
|
||||
use exo_core::{EntityId, Relation, RelationType};
|
||||
use exo_hypergraph::{HypergraphConfig, HypergraphSubstrate};
|
||||
|
||||
fn create_test_hypergraph() -> HypergraphSubstrate {
|
||||
let config = HypergraphConfig::default();
|
||||
HypergraphSubstrate::new(config)
|
||||
}
|
||||
|
||||
fn benchmark_hyperedge_creation(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("hypergraph_edge_creation");
|
||||
|
||||
for edge_size in [2, 5, 10, 20].iter() {
|
||||
let mut graph = create_test_hypergraph();
|
||||
|
||||
// Pre-create entities
|
||||
let mut entities = Vec::new();
|
||||
for _ in 0..100 {
|
||||
let entity = EntityId::new();
|
||||
graph.add_entity(entity, serde_json::json!({}));
|
||||
entities.push(entity);
|
||||
}
|
||||
|
||||
let relation = Relation {
|
||||
relation_type: RelationType::new("test"),
|
||||
properties: serde_json::json!({"weight": 0.9}),
|
||||
};
|
||||
|
||||
group.bench_with_input(
|
||||
BenchmarkId::from_parameter(edge_size),
|
||||
edge_size,
|
||||
|b, &size| {
|
||||
b.iter(|| {
|
||||
let entity_set: Vec<EntityId> = entities.iter().take(size).copied().collect();
|
||||
graph.create_hyperedge(black_box(&entity_set), black_box(&relation))
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
group.finish();
|
||||
}
|
||||
|
||||
fn benchmark_query_performance(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("hypergraph_query");
|
||||
|
||||
for num_edges in [100, 500, 1000].iter() {
|
||||
let mut graph = create_test_hypergraph();
|
||||
|
||||
// Create entities
|
||||
let mut entities = Vec::new();
|
||||
for _ in 0..200 {
|
||||
let entity = EntityId::new();
|
||||
graph.add_entity(entity, serde_json::json!({}));
|
||||
entities.push(entity);
|
||||
}
|
||||
|
||||
// Create hyperedges
|
||||
let relation = Relation {
|
||||
relation_type: RelationType::new("test"),
|
||||
properties: serde_json::json!({}),
|
||||
};
|
||||
|
||||
for _ in 0..*num_edges {
|
||||
let entity_set: Vec<EntityId> = entities.iter().take(5).copied().collect();
|
||||
graph.create_hyperedge(&entity_set, &relation).unwrap();
|
||||
}
|
||||
|
||||
let query_entity = entities[0];
|
||||
|
||||
group.bench_with_input(BenchmarkId::from_parameter(num_edges), num_edges, |b, _| {
|
||||
b.iter(|| graph.hyperedges_for_entity(black_box(&query_entity)));
|
||||
});
|
||||
}
|
||||
|
||||
group.finish();
|
||||
}
|
||||
|
||||
fn benchmark_betti_numbers(c: &mut Criterion) {
|
||||
let mut graph = create_test_hypergraph();
|
||||
|
||||
// Create a complex structure
|
||||
let mut entities = Vec::new();
|
||||
for _ in 0..100 {
|
||||
let entity = EntityId::new();
|
||||
graph.add_entity(entity, serde_json::json!({}));
|
||||
entities.push(entity);
|
||||
}
|
||||
|
||||
let relation = Relation {
|
||||
relation_type: RelationType::new("test"),
|
||||
properties: serde_json::json!({}),
|
||||
};
|
||||
|
||||
for _ in 0..500 {
|
||||
let entity_set: Vec<EntityId> = entities.iter().take(5).copied().collect();
|
||||
graph.create_hyperedge(&entity_set, &relation).unwrap();
|
||||
}
|
||||
|
||||
c.bench_function("hypergraph_betti_numbers", |b| {
|
||||
b.iter(|| graph.betti_numbers(black_box(3)));
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(
|
||||
benches,
|
||||
benchmark_hyperedge_creation,
|
||||
benchmark_query_performance,
|
||||
benchmark_betti_numbers
|
||||
);
|
||||
criterion_main!(benches);
|
||||
102
vendor/ruvector/examples/exo-ai-2025/benches/manifold_bench.rs
vendored
Normal file
102
vendor/ruvector/examples/exo-ai-2025/benches/manifold_bench.rs
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
use burn::backend::NdArray;
|
||||
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
|
||||
use exo_core::{ManifoldConfig, Metadata, Pattern, PatternId, SubstrateTime};
|
||||
use exo_manifold::ManifoldEngine;
|
||||
|
||||
type TestBackend = NdArray;
|
||||
|
||||
fn create_test_engine() -> ManifoldEngine<TestBackend> {
|
||||
let config = ManifoldConfig {
|
||||
dimension: 512,
|
||||
hidden_dim: 256,
|
||||
hidden_layers: 4,
|
||||
omega_0: 30.0,
|
||||
learning_rate: 0.01,
|
||||
max_descent_steps: 50,
|
||||
..Default::default()
|
||||
};
|
||||
let device = Default::default();
|
||||
ManifoldEngine::<TestBackend>::new(config, device)
|
||||
}
|
||||
|
||||
fn create_test_pattern(dim: usize, salience: f32) -> Pattern {
|
||||
Pattern {
|
||||
id: PatternId::new(),
|
||||
embedding: vec![0.5; dim],
|
||||
metadata: Metadata::default(),
|
||||
timestamp: SubstrateTime::now(),
|
||||
antecedents: vec![],
|
||||
salience,
|
||||
}
|
||||
}
|
||||
|
||||
fn benchmark_retrieval(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("manifold_retrieval");
|
||||
|
||||
for num_patterns in [100, 500, 1000].iter() {
|
||||
let mut engine = create_test_engine();
|
||||
|
||||
// Pre-populate with patterns
|
||||
for _ in 0..*num_patterns {
|
||||
let pattern = create_test_pattern(512, 0.7);
|
||||
engine.deform(pattern, 0.7).unwrap();
|
||||
}
|
||||
|
||||
let query = vec![0.5; 512];
|
||||
|
||||
group.bench_with_input(
|
||||
BenchmarkId::from_parameter(num_patterns),
|
||||
num_patterns,
|
||||
|b, _| {
|
||||
b.iter(|| engine.retrieve(black_box(&query), black_box(10)));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
group.finish();
|
||||
}
|
||||
|
||||
fn benchmark_deformation(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("manifold_deformation");
|
||||
|
||||
for batch_size in [10, 50, 100].iter() {
|
||||
group.bench_with_input(
|
||||
BenchmarkId::from_parameter(batch_size),
|
||||
batch_size,
|
||||
|b, &size| {
|
||||
b.iter(|| {
|
||||
let mut engine = create_test_engine();
|
||||
for _ in 0..size {
|
||||
let pattern = create_test_pattern(512, 0.8);
|
||||
engine.deform(black_box(pattern), black_box(0.8)).unwrap();
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
group.finish();
|
||||
}
|
||||
|
||||
fn benchmark_forgetting(c: &mut Criterion) {
|
||||
let mut engine = create_test_engine();
|
||||
|
||||
// Pre-populate
|
||||
for i in 0..500 {
|
||||
let salience = if i < 100 { 0.9 } else { 0.3 };
|
||||
let pattern = create_test_pattern(512, salience);
|
||||
engine.deform(pattern, salience).unwrap();
|
||||
}
|
||||
|
||||
c.bench_function("manifold_forgetting", |b| {
|
||||
b.iter(|| engine.forget(black_box(0.5), black_box(0.1)));
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(
|
||||
benches,
|
||||
benchmark_retrieval,
|
||||
benchmark_deformation,
|
||||
benchmark_forgetting
|
||||
);
|
||||
criterion_main!(benches);
|
||||
57
vendor/ruvector/examples/exo-ai-2025/benches/run_benchmarks.sh
vendored
Executable file
57
vendor/ruvector/examples/exo-ai-2025/benches/run_benchmarks.sh
vendored
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
# EXO-AI 2025 Benchmark Runner
|
||||
# Performance analysis suite for cognitive substrate
|
||||
|
||||
set -e
|
||||
|
||||
PROJECT_ROOT="/home/user/ruvector/examples/exo-ai-2025"
|
||||
RESULTS_DIR="$PROJECT_ROOT/target/criterion"
|
||||
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
echo "======================================"
|
||||
echo "EXO-AI 2025 Performance Benchmarks"
|
||||
echo "======================================"
|
||||
echo ""
|
||||
|
||||
# Check if crates compile first
|
||||
echo "Step 1: Checking crate compilation..."
|
||||
if cargo check --benches; then
|
||||
echo "✓ All crates compile successfully"
|
||||
else
|
||||
echo "✗ Compilation errors detected. Please fix before benchmarking."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Step 2: Running benchmark suites..."
|
||||
echo ""
|
||||
|
||||
# Run all benchmarks
|
||||
echo "→ Running Manifold benchmarks..."
|
||||
cargo bench --bench manifold_bench
|
||||
|
||||
echo ""
|
||||
echo "→ Running Hypergraph benchmarks..."
|
||||
cargo bench --bench hypergraph_bench
|
||||
|
||||
echo ""
|
||||
echo "→ Running Temporal benchmarks..."
|
||||
cargo bench --bench temporal_bench
|
||||
|
||||
echo ""
|
||||
echo "→ Running Federation benchmarks..."
|
||||
cargo bench --bench federation_bench
|
||||
|
||||
echo ""
|
||||
echo "======================================"
|
||||
echo "Benchmark Complete!"
|
||||
echo "======================================"
|
||||
echo ""
|
||||
echo "Results saved to: $RESULTS_DIR"
|
||||
echo "HTML reports available at: $RESULTS_DIR/report/index.html"
|
||||
echo ""
|
||||
echo "To compare against baseline:"
|
||||
echo " cargo bench -- --save-baseline initial"
|
||||
echo " cargo bench -- --baseline initial"
|
||||
echo ""
|
||||
119
vendor/ruvector/examples/exo-ai-2025/benches/temporal_bench.rs
vendored
Normal file
119
vendor/ruvector/examples/exo-ai-2025/benches/temporal_bench.rs
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
|
||||
use exo_core::{Metadata, Pattern, PatternId, Query, SubstrateTime};
|
||||
use exo_temporal::{CausalConeType, TemporalConfig, TemporalMemory};
|
||||
|
||||
fn create_test_memory() -> TemporalMemory {
|
||||
TemporalMemory::new(TemporalConfig::default())
|
||||
}
|
||||
|
||||
fn create_test_pattern(embedding: Vec<f32>) -> Pattern {
|
||||
Pattern::new(embedding, Metadata::new())
|
||||
}
|
||||
|
||||
fn benchmark_causal_query(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("temporal_causal_query");
|
||||
|
||||
for num_events in [100, 500, 1000].iter() {
|
||||
let memory = create_test_memory();
|
||||
|
||||
// Pre-populate with events in causal chain
|
||||
let mut pattern_ids = Vec::new();
|
||||
for i in 0..*num_events {
|
||||
let embedding = vec![0.5; 128];
|
||||
let pattern = create_test_pattern(embedding);
|
||||
let antecedents = if i > 0 && i % 10 == 0 {
|
||||
vec![pattern_ids[i - 1]]
|
||||
} else {
|
||||
vec![]
|
||||
};
|
||||
let id = memory.store(pattern, &antecedents).unwrap();
|
||||
pattern_ids.push(id);
|
||||
}
|
||||
|
||||
// Consolidate to long-term
|
||||
memory.consolidate();
|
||||
|
||||
let query = Query::from_embedding(vec![0.5; 128]);
|
||||
|
||||
group.bench_with_input(
|
||||
BenchmarkId::from_parameter(num_events),
|
||||
num_events,
|
||||
|b, _| {
|
||||
b.iter(|| {
|
||||
memory.causal_query(
|
||||
black_box(&query),
|
||||
black_box(SubstrateTime::now()),
|
||||
black_box(CausalConeType::Past),
|
||||
)
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
group.finish();
|
||||
}
|
||||
|
||||
fn benchmark_consolidation(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("temporal_consolidation");
|
||||
|
||||
for num_events in [100, 500, 1000].iter() {
|
||||
group.bench_with_input(
|
||||
BenchmarkId::from_parameter(num_events),
|
||||
num_events,
|
||||
|b, &events| {
|
||||
b.iter(|| {
|
||||
let memory = create_test_memory();
|
||||
// Fill short-term buffer
|
||||
for _ in 0..events {
|
||||
let embedding = vec![0.5; 128];
|
||||
let pattern = create_test_pattern(embedding);
|
||||
memory.store(pattern, &[]).unwrap();
|
||||
}
|
||||
// Benchmark consolidation
|
||||
memory.consolidate()
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
group.finish();
|
||||
}
|
||||
|
||||
fn benchmark_pattern_storage(c: &mut Criterion) {
|
||||
let memory = create_test_memory();
|
||||
|
||||
c.bench_function("temporal_pattern_storage", |b| {
|
||||
b.iter(|| {
|
||||
let embedding = vec![0.5; 128];
|
||||
let pattern = create_test_pattern(embedding);
|
||||
memory.store(black_box(pattern), black_box(&[]))
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn benchmark_pattern_retrieval(c: &mut Criterion) {
|
||||
let memory = create_test_memory();
|
||||
|
||||
// Pre-populate
|
||||
let mut pattern_ids = Vec::new();
|
||||
for _ in 0..1000 {
|
||||
let embedding = vec![0.5; 128];
|
||||
let pattern = create_test_pattern(embedding);
|
||||
let id = memory.store(pattern, &[]).unwrap();
|
||||
pattern_ids.push(id);
|
||||
}
|
||||
|
||||
c.bench_function("temporal_pattern_retrieval", |b| {
|
||||
let query_id = pattern_ids[500];
|
||||
b.iter(|| memory.get(black_box(&query_id)));
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(
|
||||
benches,
|
||||
benchmark_causal_query,
|
||||
benchmark_consolidation,
|
||||
benchmark_pattern_storage,
|
||||
benchmark_pattern_retrieval
|
||||
);
|
||||
criterion_main!(benches);
|
||||
Reference in New Issue
Block a user