Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# Generated by Cargo
# will have compiled files and executables
debug
target

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# Generated by cargo mutants
# Contains mutation testing data
**/mutants.out*/

# RustRover
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Both databases used to store and retrieve doublet-links representation. To suppo
## Results
The results below represent the amount of time (ns) the operation takes per iteration.
- First picture shows time in a pixel scale (for doublets just minimum value is shown, otherwise it will be not present on the graph).
- Second picture shows time in a logarithmic scale (to see diffrence clearly, because it is around 2-3 orders of magnitude).
- Second picture shows time in a logarithmic scale (to see difference clearly, because it is around 2-3 orders of magnitude).

### Rust
![Image of Rust benchmark (pixel scale)](https://github.com/linksplatform/Comparisons.PostgreSQLVSDoublets/blob/main/Docs/bench_rust.png?raw=true)
Expand Down
42 changes: 30 additions & 12 deletions rust/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

use {
benchmarks::{
create_links, delete_links, each_all, each_concrete, each_identity, each_incoming,
each_outgoing, update_links,
doublets_create_links, doublets_delete_links, doublets_each_all, doublets_each_concrete,
doublets_each_identity, doublets_each_incoming, doublets_each_outgoing,
doublets_update_links, psql_create_links, psql_delete_links, psql_each_all,
psql_each_concrete, psql_each_identity, psql_each_incoming, psql_each_outgoing,
psql_update_links,
},
criterion::{criterion_group, criterion_main},
};
Expand All @@ -20,15 +23,30 @@ macro_rules! tri {

pub(crate) use tri;

// PostgreSQL benchmarks
criterion_group!(
benches,
create_links,
delete_links,
each_identity,
each_concrete,
each_outgoing,
each_incoming,
each_all,
update_links
psql_benches,
psql_create_links,
psql_delete_links,
psql_each_identity,
psql_each_concrete,
psql_each_outgoing,
psql_each_incoming,
psql_each_all,
psql_update_links
);
criterion_main!(benches);

// Doublets benchmarks
criterion_group!(
doublets_benches,
doublets_create_links,
doublets_delete_links,
doublets_each_identity,
doublets_each_concrete,
doublets_each_outgoing,
doublets_each_incoming,
doublets_each_all,
doublets_update_links
);

criterion_main!(psql_benches, doublets_benches);
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
use {
crate::tri,
criterion::{BenchmarkGroup, Criterion, measurement::WallTime},
doublets::{
data::LinkType,
Doublets,
mem::{Alloc, FileMapped},
parts::LinkPart,
split::{self, DataPart, IndexPart}, unit,
},
linkspsql::{bench, benchmark_links, Benched, Client, connect, Exclusive, Fork, Transaction},
std::{alloc::Global, time::{Duration, Instant}},
//! # Doublets Create Links Benchmark
//!
//! This benchmark measures the performance of creating new links in Doublets.
//!
//! ## Implementation
//!
//! Doublets creates links by:
//! - Allocating next available ID from internal counter
//! - Writing (id, id, id) tuple directly to memory/file
//! - Updating source and target indexes
//! - Time complexity: O(log n) for index updates

use std::{
alloc::Global,
time::{Duration, Instant},
};

use criterion::{measurement::WallTime, BenchmarkGroup, Criterion};
use doublets::{
mem::{Alloc, FileMapped},
parts::LinkPart,
split::{self, DataPart, IndexPart},
unit, Doublets,
};
use linkspsql::{bench, benchmark_links, Benched, Fork};

fn bench<T: LinkType, B: Benched + Doublets<T>>(
use crate::tri;

/// Runs the create benchmark on a Doublets backend.
fn bench<B: Benched + Doublets<usize>>(
group: &mut BenchmarkGroup<WallTime>,
id: &str,
mut benched: B,
Expand All @@ -27,19 +42,10 @@ fn bench<T: LinkType, B: Benched + Doublets<T>>(
});
}

/// Creates benchmark for Doublets backends on link creation.
pub fn create_links(c: &mut Criterion) {
let mut group = c.benchmark_group("Create");
tri! {
bench(&mut group, "PSQL_NonTransaction", Exclusive::<Client<usize>>::setup(()).unwrap());
}
tri! {
let mut client = connect().unwrap();
bench(
&mut group,
"PSQL_Transaction",
Exclusive::<Transaction<'_, usize>>::setup(&mut client).unwrap(),
);
}

tri! {
bench(
&mut group,
Expand Down Expand Up @@ -68,5 +74,6 @@ pub fn create_links(c: &mut Criterion) {
split::Store::<usize, FileMapped<_>, FileMapped<_>>::setup(("split_index.links", "split_data.links")).unwrap()
)
}

group.finish();
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
use {
crate::tri,
criterion::{BenchmarkGroup, Criterion, measurement::WallTime},
doublets::{
Doublets,
mem::{Alloc, FileMapped},
parts::LinkPart,
split::{self, DataPart, IndexPart}, unit,
},
linkspsql::{bench, background_links, benchmark_links, Benched, Client, connect, Exclusive, Fork, Transaction},
std::{alloc::Global, time::{Duration, Instant}},
//! # Doublets Delete Links Benchmark
//!
//! This benchmark measures the performance of deleting links in Doublets.
//!
//! ## Implementation
//!
//! Doublets deletes links by:
//! - Removing the link from source and target indexes
//! - Marking the slot as free for reuse
//! - Time complexity: O(log n) for index updates

use std::{
alloc::Global,
time::{Duration, Instant},
};

use criterion::{measurement::WallTime, BenchmarkGroup, Criterion};
use doublets::{
mem::{Alloc, FileMapped},
parts::LinkPart,
split::{self, DataPart, IndexPart},
unit, Doublets,
};
use linkspsql::{background_links, bench, benchmark_links, Benched, Fork};

use crate::tri;

/// Runs the delete benchmark on a Doublets backend.
fn bench<B: Benched + Doublets<usize>>(
group: &mut BenchmarkGroup<WallTime>,
id: &str,
Expand All @@ -29,19 +45,10 @@ fn bench<B: Benched + Doublets<usize>>(
});
}

/// Creates benchmark for Doublets backends on link deletion.
pub fn delete_links(c: &mut Criterion) {
let mut group = c.benchmark_group("Delete");
tri! {
bench(&mut group, "PSQL_NonTransaction", Exclusive::<Client<usize>>::setup(()).unwrap());
}
tri! {
let mut client = connect().unwrap();
bench(
&mut group,
"PSQL_Transaction",
Exclusive::<Transaction<'_, usize>>::setup(&mut client).unwrap(),
);
}

tri! {
bench(
&mut group,
Expand Down Expand Up @@ -70,5 +77,6 @@ pub fn delete_links(c: &mut Criterion) {
split::Store::<usize, FileMapped<_>, FileMapped<_>>::setup(("split_index.links", "split_data.links")).unwrap()
)
}

group.finish();
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
use {
crate::tri,
criterion::{measurement::WallTime, BenchmarkGroup, Criterion},
doublets::{
data::{Flow, LinkType},
mem::{Alloc, FileMapped},
parts::LinkPart,
split::{self, DataPart, IndexPart},
unit, Doublets,
},
linkspsql::{bench, connect, Benched, Client, Exclusive, Fork, Transaction},
std::{
alloc::Global,
time::{Duration, Instant},
},
//! # Doublets Each All Benchmark
//!
//! This benchmark measures the performance of querying all links in Doublets.
//!
//! ## Implementation
//!
//! Query pattern: `[*, *, *]` - matches all links
//! - Sequential iteration through the internal array
//! - Time complexity: O(n) where n is the number of links

use std::{
alloc::Global,
time::{Duration, Instant},
};

use criterion::{measurement::WallTime, BenchmarkGroup, Criterion};
use doublets::{
data::Flow,
mem::{Alloc, FileMapped},
parts::LinkPart,
split::{self, DataPart, IndexPart},
unit, Doublets,
};
use linkspsql::{bench, Benched, Fork};

fn bench<T: LinkType, B: Benched + Doublets<T>>(
use crate::tri;

/// Runs the each_all benchmark on a Doublets backend.
fn bench<B: Benched + Doublets<usize>>(
group: &mut BenchmarkGroup<WallTime>,
id: &str,
mut benched: B,
Expand All @@ -28,19 +39,10 @@ fn bench<T: LinkType, B: Benched + Doublets<T>>(
});
}

/// Creates benchmark for Doublets backends on querying all links.
pub fn each_all(c: &mut Criterion) {
let mut group = c.benchmark_group("Each_All");
tri! {
bench(&mut group, "PSQL_NonTransaction", Exclusive::<Client<usize>>::setup(()).unwrap());
}
tri! {
let mut client = connect().unwrap();
bench(
&mut group,
"PSQL_Transaction",
Exclusive::<Transaction<'_, usize>>::setup(&mut client).unwrap(),
);
}

tri! {
bench(
&mut group,
Expand Down Expand Up @@ -69,5 +71,6 @@ pub fn each_all(c: &mut Criterion) {
split::Store::<usize, FileMapped<_>, FileMapped<_>>::setup(("split_index.links", "split_data.links")).unwrap()
)
}

group.finish();
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
use {
crate::tri,
criterion::{measurement::WallTime, BenchmarkGroup, Criterion},
doublets::{
data::{Flow, LinksConstants},
mem::{Alloc, FileMapped},
parts::LinkPart,
split::{self, DataPart, IndexPart},
unit, Doublets,
},
linkspsql::{background_links, bench, connect, Benched, Client, Exclusive, Fork, Transaction},
std::{
alloc::Global,
time::{Duration, Instant},
},
//! # Doublets Each Concrete Benchmark
//!
//! This benchmark measures the performance of querying links by source+target in Doublets.
//!
//! ## Implementation
//!
//! Query pattern: `[*, src, tgt]` - matches links by source and target
//! - Index tree lookup followed by filter
//! - Time complexity: O(log n) for index lookup

use std::{
alloc::Global,
time::{Duration, Instant},
};

use criterion::{measurement::WallTime, BenchmarkGroup, Criterion};
use doublets::{
data::{Flow, LinksConstants},
mem::{Alloc, FileMapped},
parts::LinkPart,
split::{self, DataPart, IndexPart},
unit, Doublets,
};
use linkspsql::{background_links, bench, Benched, Fork};

use crate::tri;

/// Runs the each_concrete benchmark on a Doublets backend.
fn bench<B: Benched + Doublets<usize>>(
group: &mut BenchmarkGroup<WallTime>,
id: &str,
Expand All @@ -31,19 +43,10 @@ fn bench<B: Benched + Doublets<usize>>(
});
}

/// Creates benchmark for Doublets backends on querying links by source+target.
pub fn each_concrete(c: &mut Criterion) {
let mut group = c.benchmark_group("Each_Concrete");
tri! {
bench(&mut group, "PSQL_NonTransaction", Exclusive::<Client<usize>>::setup(()).unwrap());
}
tri! {
let mut client = connect().unwrap();
bench(
&mut group,
"PSQL_Transaction",
Exclusive::<Transaction<'_, usize>>::setup(&mut client).unwrap(),
);
}

tri! {
bench(
&mut group,
Expand Down Expand Up @@ -72,5 +75,6 @@ pub fn each_concrete(c: &mut Criterion) {
split::Store::<usize, FileMapped<_>, FileMapped<_>>::setup(("split_index.links", "split_data.links")).unwrap()
)
}

group.finish();
}
Loading