Skip to content

Commit 0e0cc99

Browse files
authored
Merge pull request #20 from linksplatform/issue-19-2da718a4317b
Reorganize Rust benchmark file structure following Neo4jVSDoublets pattern
2 parents 707b41f + 91ec1af commit 0e0cc99

29 files changed

+1144
-337
lines changed

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
# Generated by Cargo
2+
# will have compiled files and executables
3+
debug
4+
target
5+
6+
# These are backup files generated by rustfmt
7+
**/*.rs.bk
8+
9+
# MSVC Windows builds of rustc generate these, which store debugging information
10+
*.pdb
11+
12+
# Generated by cargo mutants
13+
# Contains mutation testing data
14+
**/mutants.out*/
15+
16+
# RustRover
17+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
18+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
19+
# and can be added to the global gitignore or merged into this file. For a more nuclear
20+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
21+
#.idea/
22+
123
## Ignore Visual Studio temporary files, build results, and
224
## files generated by popular Visual Studio add-ons.
325
##

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Both databases used to store and retrieve doublet-links representation. To suppo
2222
## Results
2323
The results below represent the amount of time (ns) the operation takes per iteration.
2424
- First picture shows time in a pixel scale (for doublets just minimum value is shown, otherwise it will be not present on the graph).
25-
- Second picture shows time in a logarithmic scale (to see diffrence clearly, because it is around 2-3 orders of magnitude).
25+
- Second picture shows time in a logarithmic scale (to see difference clearly, because it is around 2-3 orders of magnitude).
2626

2727
### Rust
2828
![Image of Rust benchmark (pixel scale)](https://github.com/linksplatform/Comparisons.PostgreSQLVSDoublets/blob/main/Docs/bench_rust.png?raw=true)

rust/benches/bench.rs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
use {
44
benchmarks::{
5-
create_links, delete_links, each_all, each_concrete, each_identity, each_incoming,
6-
each_outgoing, update_links,
5+
doublets_create_links, doublets_delete_links, doublets_each_all, doublets_each_concrete,
6+
doublets_each_identity, doublets_each_incoming, doublets_each_outgoing,
7+
doublets_update_links, psql_create_links, psql_delete_links, psql_each_all,
8+
psql_each_concrete, psql_each_identity, psql_each_incoming, psql_each_outgoing,
9+
psql_update_links,
710
},
811
criterion::{criterion_group, criterion_main},
912
};
@@ -20,15 +23,30 @@ macro_rules! tri {
2023

2124
pub(crate) use tri;
2225

26+
// PostgreSQL benchmarks
2327
criterion_group!(
24-
benches,
25-
create_links,
26-
delete_links,
27-
each_identity,
28-
each_concrete,
29-
each_outgoing,
30-
each_incoming,
31-
each_all,
32-
update_links
28+
psql_benches,
29+
psql_create_links,
30+
psql_delete_links,
31+
psql_each_identity,
32+
psql_each_concrete,
33+
psql_each_outgoing,
34+
psql_each_incoming,
35+
psql_each_all,
36+
psql_update_links
3337
);
34-
criterion_main!(benches);
38+
39+
// Doublets benchmarks
40+
criterion_group!(
41+
doublets_benches,
42+
doublets_create_links,
43+
doublets_delete_links,
44+
doublets_each_identity,
45+
doublets_each_concrete,
46+
doublets_each_outgoing,
47+
doublets_each_incoming,
48+
doublets_each_all,
49+
doublets_update_links
50+
);
51+
52+
criterion_main!(psql_benches, doublets_benches);

rust/benches/benchmarks/create.rs renamed to rust/benches/benchmarks/doublets/create.rs

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
1-
use {
2-
crate::tri,
3-
criterion::{BenchmarkGroup, Criterion, measurement::WallTime},
4-
doublets::{
5-
data::LinkType,
6-
Doublets,
7-
mem::{Alloc, FileMapped},
8-
parts::LinkPart,
9-
split::{self, DataPart, IndexPart}, unit,
10-
},
11-
linkspsql::{bench, benchmark_links, Benched, Client, connect, Exclusive, Fork, Transaction},
12-
std::{alloc::Global, time::{Duration, Instant}},
1+
//! # Doublets Create Links Benchmark
2+
//!
3+
//! This benchmark measures the performance of creating new links in Doublets.
4+
//!
5+
//! ## Implementation
6+
//!
7+
//! Doublets creates links by:
8+
//! - Allocating next available ID from internal counter
9+
//! - Writing (id, id, id) tuple directly to memory/file
10+
//! - Updating source and target indexes
11+
//! - Time complexity: O(log n) for index updates
12+
13+
use std::{
14+
alloc::Global,
15+
time::{Duration, Instant},
16+
};
17+
18+
use criterion::{measurement::WallTime, BenchmarkGroup, Criterion};
19+
use doublets::{
20+
mem::{Alloc, FileMapped},
21+
parts::LinkPart,
22+
split::{self, DataPart, IndexPart},
23+
unit, Doublets,
1324
};
25+
use linkspsql::{bench, benchmark_links, Benched, Fork};
1426

15-
fn bench<T: LinkType, B: Benched + Doublets<T>>(
27+
use crate::tri;
28+
29+
/// Runs the create benchmark on a Doublets backend.
30+
fn bench<B: Benched + Doublets<usize>>(
1631
group: &mut BenchmarkGroup<WallTime>,
1732
id: &str,
1833
mut benched: B,
@@ -27,19 +42,10 @@ fn bench<T: LinkType, B: Benched + Doublets<T>>(
2742
});
2843
}
2944

45+
/// Creates benchmark for Doublets backends on link creation.
3046
pub fn create_links(c: &mut Criterion) {
3147
let mut group = c.benchmark_group("Create");
32-
tri! {
33-
bench(&mut group, "PSQL_NonTransaction", Exclusive::<Client<usize>>::setup(()).unwrap());
34-
}
35-
tri! {
36-
let mut client = connect().unwrap();
37-
bench(
38-
&mut group,
39-
"PSQL_Transaction",
40-
Exclusive::<Transaction<'_, usize>>::setup(&mut client).unwrap(),
41-
);
42-
}
48+
4349
tri! {
4450
bench(
4551
&mut group,
@@ -68,5 +74,6 @@ pub fn create_links(c: &mut Criterion) {
6874
split::Store::<usize, FileMapped<_>, FileMapped<_>>::setup(("split_index.links", "split_data.links")).unwrap()
6975
)
7076
}
77+
7178
group.finish();
7279
}

rust/benches/benchmarks/delete.rs renamed to rust/benches/benchmarks/doublets/delete.rs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
1-
use {
2-
crate::tri,
3-
criterion::{BenchmarkGroup, Criterion, measurement::WallTime},
4-
doublets::{
5-
Doublets,
6-
mem::{Alloc, FileMapped},
7-
parts::LinkPart,
8-
split::{self, DataPart, IndexPart}, unit,
9-
},
10-
linkspsql::{bench, background_links, benchmark_links, Benched, Client, connect, Exclusive, Fork, Transaction},
11-
std::{alloc::Global, time::{Duration, Instant}},
1+
//! # Doublets Delete Links Benchmark
2+
//!
3+
//! This benchmark measures the performance of deleting links in Doublets.
4+
//!
5+
//! ## Implementation
6+
//!
7+
//! Doublets deletes links by:
8+
//! - Removing the link from source and target indexes
9+
//! - Marking the slot as free for reuse
10+
//! - Time complexity: O(log n) for index updates
11+
12+
use std::{
13+
alloc::Global,
14+
time::{Duration, Instant},
15+
};
16+
17+
use criterion::{measurement::WallTime, BenchmarkGroup, Criterion};
18+
use doublets::{
19+
mem::{Alloc, FileMapped},
20+
parts::LinkPart,
21+
split::{self, DataPart, IndexPart},
22+
unit, Doublets,
1223
};
24+
use linkspsql::{background_links, bench, benchmark_links, Benched, Fork};
25+
26+
use crate::tri;
27+
28+
/// Runs the delete benchmark on a Doublets backend.
1329
fn bench<B: Benched + Doublets<usize>>(
1430
group: &mut BenchmarkGroup<WallTime>,
1531
id: &str,
@@ -29,19 +45,10 @@ fn bench<B: Benched + Doublets<usize>>(
2945
});
3046
}
3147

48+
/// Creates benchmark for Doublets backends on link deletion.
3249
pub fn delete_links(c: &mut Criterion) {
3350
let mut group = c.benchmark_group("Delete");
34-
tri! {
35-
bench(&mut group, "PSQL_NonTransaction", Exclusive::<Client<usize>>::setup(()).unwrap());
36-
}
37-
tri! {
38-
let mut client = connect().unwrap();
39-
bench(
40-
&mut group,
41-
"PSQL_Transaction",
42-
Exclusive::<Transaction<'_, usize>>::setup(&mut client).unwrap(),
43-
);
44-
}
51+
4552
tri! {
4653
bench(
4754
&mut group,
@@ -70,5 +77,6 @@ pub fn delete_links(c: &mut Criterion) {
7077
split::Store::<usize, FileMapped<_>, FileMapped<_>>::setup(("split_index.links", "split_data.links")).unwrap()
7178
)
7279
}
80+
7381
group.finish();
7482
}
Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
1-
use {
2-
crate::tri,
3-
criterion::{measurement::WallTime, BenchmarkGroup, Criterion},
4-
doublets::{
5-
data::{Flow, LinkType},
6-
mem::{Alloc, FileMapped},
7-
parts::LinkPart,
8-
split::{self, DataPart, IndexPart},
9-
unit, Doublets,
10-
},
11-
linkspsql::{bench, connect, Benched, Client, Exclusive, Fork, Transaction},
12-
std::{
13-
alloc::Global,
14-
time::{Duration, Instant},
15-
},
1+
//! # Doublets Each All Benchmark
2+
//!
3+
//! This benchmark measures the performance of querying all links in Doublets.
4+
//!
5+
//! ## Implementation
6+
//!
7+
//! Query pattern: `[*, *, *]` - matches all links
8+
//! - Sequential iteration through the internal array
9+
//! - Time complexity: O(n) where n is the number of links
10+
11+
use std::{
12+
alloc::Global,
13+
time::{Duration, Instant},
14+
};
15+
16+
use criterion::{measurement::WallTime, BenchmarkGroup, Criterion};
17+
use doublets::{
18+
data::Flow,
19+
mem::{Alloc, FileMapped},
20+
parts::LinkPart,
21+
split::{self, DataPart, IndexPart},
22+
unit, Doublets,
1623
};
24+
use linkspsql::{bench, Benched, Fork};
1725

18-
fn bench<T: LinkType, B: Benched + Doublets<T>>(
26+
use crate::tri;
27+
28+
/// Runs the each_all benchmark on a Doublets backend.
29+
fn bench<B: Benched + Doublets<usize>>(
1930
group: &mut BenchmarkGroup<WallTime>,
2031
id: &str,
2132
mut benched: B,
@@ -28,19 +39,10 @@ fn bench<T: LinkType, B: Benched + Doublets<T>>(
2839
});
2940
}
3041

42+
/// Creates benchmark for Doublets backends on querying all links.
3143
pub fn each_all(c: &mut Criterion) {
3244
let mut group = c.benchmark_group("Each_All");
33-
tri! {
34-
bench(&mut group, "PSQL_NonTransaction", Exclusive::<Client<usize>>::setup(()).unwrap());
35-
}
36-
tri! {
37-
let mut client = connect().unwrap();
38-
bench(
39-
&mut group,
40-
"PSQL_Transaction",
41-
Exclusive::<Transaction<'_, usize>>::setup(&mut client).unwrap(),
42-
);
43-
}
45+
4446
tri! {
4547
bench(
4648
&mut group,
@@ -69,5 +71,6 @@ pub fn each_all(c: &mut Criterion) {
6971
split::Store::<usize, FileMapped<_>, FileMapped<_>>::setup(("split_index.links", "split_data.links")).unwrap()
7072
)
7173
}
74+
7275
group.finish();
7376
}

rust/benches/benchmarks/each/concrete.rs renamed to rust/benches/benchmarks/doublets/each/concrete.rs

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
1-
use {
2-
crate::tri,
3-
criterion::{measurement::WallTime, BenchmarkGroup, Criterion},
4-
doublets::{
5-
data::{Flow, LinksConstants},
6-
mem::{Alloc, FileMapped},
7-
parts::LinkPart,
8-
split::{self, DataPart, IndexPart},
9-
unit, Doublets,
10-
},
11-
linkspsql::{background_links, bench, connect, Benched, Client, Exclusive, Fork, Transaction},
12-
std::{
13-
alloc::Global,
14-
time::{Duration, Instant},
15-
},
1+
//! # Doublets Each Concrete Benchmark
2+
//!
3+
//! This benchmark measures the performance of querying links by source+target in Doublets.
4+
//!
5+
//! ## Implementation
6+
//!
7+
//! Query pattern: `[*, src, tgt]` - matches links by source and target
8+
//! - Index tree lookup followed by filter
9+
//! - Time complexity: O(log n) for index lookup
10+
11+
use std::{
12+
alloc::Global,
13+
time::{Duration, Instant},
14+
};
15+
16+
use criterion::{measurement::WallTime, BenchmarkGroup, Criterion};
17+
use doublets::{
18+
data::{Flow, LinksConstants},
19+
mem::{Alloc, FileMapped},
20+
parts::LinkPart,
21+
split::{self, DataPart, IndexPart},
22+
unit, Doublets,
1623
};
24+
use linkspsql::{background_links, bench, Benched, Fork};
25+
26+
use crate::tri;
27+
28+
/// Runs the each_concrete benchmark on a Doublets backend.
1729
fn bench<B: Benched + Doublets<usize>>(
1830
group: &mut BenchmarkGroup<WallTime>,
1931
id: &str,
@@ -31,19 +43,10 @@ fn bench<B: Benched + Doublets<usize>>(
3143
});
3244
}
3345

46+
/// Creates benchmark for Doublets backends on querying links by source+target.
3447
pub fn each_concrete(c: &mut Criterion) {
3548
let mut group = c.benchmark_group("Each_Concrete");
36-
tri! {
37-
bench(&mut group, "PSQL_NonTransaction", Exclusive::<Client<usize>>::setup(()).unwrap());
38-
}
39-
tri! {
40-
let mut client = connect().unwrap();
41-
bench(
42-
&mut group,
43-
"PSQL_Transaction",
44-
Exclusive::<Transaction<'_, usize>>::setup(&mut client).unwrap(),
45-
);
46-
}
49+
4750
tri! {
4851
bench(
4952
&mut group,
@@ -72,5 +75,6 @@ pub fn each_concrete(c: &mut Criterion) {
7275
split::Store::<usize, FileMapped<_>, FileMapped<_>>::setup(("split_index.links", "split_data.links")).unwrap()
7376
)
7477
}
78+
7579
group.finish();
7680
}

0 commit comments

Comments
 (0)