Rename methods
This commit is contained in:
1 parent
b006ece0c1
commit
3ac7cd068b
3 files changed
+72
-33
No files matched your search
+63
-23
@@ -1,8 +1,8 @@
|
||||
use criterion::{criterion_group, criterion_main, Criterion, BenchmarkId};
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::hint::black_box;
|
||||
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
|
||||
use hashbrown::HashMap as HashbrownMap;
|
||||
use rustc_hash::FxHashMap;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::hint::black_box;
|
||||
|
||||
// Тестовая структура (аналог вашей сущности)
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -117,40 +117,60 @@ fn bench_insert(c: &mut Criterion) {
|
||||
for size in [10_000, 100_000, 500_000] {
|
||||
let entities = generate_entities(size);
|
||||
|
||||
group.bench_with_input(BenchmarkId::new("Vec (sorted)", size), &entities, |b, entities| {
|
||||
group.bench_with_input(
|
||||
BenchmarkId::new("Vec (sorted)", size),
|
||||
&entities,
|
||||
|b, entities| {
|
||||
let mut vec = Vec::with_capacity(size);
|
||||
b.iter(|| {
|
||||
bench_vec_insert_sorted(&mut vec, black_box(entities));
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
group.bench_with_input(BenchmarkId::new("BTreeMap", size), &entities, |b, entities| {
|
||||
group.bench_with_input(
|
||||
BenchmarkId::new("BTreeMap", size),
|
||||
&entities,
|
||||
|b, entities| {
|
||||
let mut map = BTreeMap::new();
|
||||
b.iter(|| {
|
||||
bench_btreemap_insert(&mut map, black_box(entities));
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
group.bench_with_input(BenchmarkId::new("HashMap (std)", size), &entities, |b, entities| {
|
||||
group.bench_with_input(
|
||||
BenchmarkId::new("HashMap (std)", size),
|
||||
&entities,
|
||||
|b, entities| {
|
||||
let mut map = HashMap::new();
|
||||
b.iter(|| {
|
||||
bench_hashmap_insert(&mut map, black_box(entities));
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
group.bench_with_input(BenchmarkId::new("HashMap (hashbrown)", size), &entities, |b, entities| {
|
||||
group.bench_with_input(
|
||||
BenchmarkId::new("HashMap (hashbrown)", size),
|
||||
&entities,
|
||||
|b, entities| {
|
||||
let mut map = HashbrownMap::new();
|
||||
b.iter(|| {
|
||||
bench_hashbrown_insert(&mut map, black_box(entities));
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
group.bench_with_input(BenchmarkId::new("FxHashMap", size), &entities, |b, entities| {
|
||||
group.bench_with_input(
|
||||
BenchmarkId::new("FxHashMap", size),
|
||||
&entities,
|
||||
|b, entities| {
|
||||
let mut map = FxHashMap::default();
|
||||
b.iter(|| {
|
||||
bench_fxhashmap_insert(&mut map, black_box(entities));
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
group.finish();
|
||||
@@ -180,21 +200,29 @@ fn bench_search(c: &mut Criterion) {
|
||||
let mut fxhashmap = FxHashMap::default();
|
||||
bench_fxhashmap_insert(&mut fxhashmap, &entities);
|
||||
|
||||
group.bench_with_input(BenchmarkId::new("Vec (binary search)", size), &search_ids, |b, ids| {
|
||||
group.bench_with_input(
|
||||
BenchmarkId::new("Vec (binary search)", size),
|
||||
&search_ids,
|
||||
|b, ids| {
|
||||
b.iter(|| {
|
||||
for &id in ids {
|
||||
black_box(bench_vec_search_separated(&entity_ids, &vec, black_box(id)));
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
group.bench_with_input(BenchmarkId::new("Vec (binary search) separated", size), &search_ids, |b, ids| {
|
||||
group.bench_with_input(
|
||||
BenchmarkId::new("Vec (binary search) separated", size),
|
||||
&search_ids,
|
||||
|b, ids| {
|
||||
b.iter(|| {
|
||||
for &id in ids {
|
||||
black_box(bench_vec_search(&vec, black_box(id)));
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
group.bench_with_input(BenchmarkId::new("BTreeMap", size), &search_ids, |b, ids| {
|
||||
b.iter(|| {
|
||||
@@ -204,29 +232,41 @@ fn bench_search(c: &mut Criterion) {
|
||||
});
|
||||
});
|
||||
|
||||
group.bench_with_input(BenchmarkId::new("HashMap (std)", size), &search_ids, |b, ids| {
|
||||
group.bench_with_input(
|
||||
BenchmarkId::new("HashMap (std)", size),
|
||||
&search_ids,
|
||||
|b, ids| {
|
||||
b.iter(|| {
|
||||
for &id in ids {
|
||||
black_box(bench_hashmap_search(&hashmap, black_box(id)));
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
group.bench_with_input(BenchmarkId::new("HashMap (hashbrown)", size), &search_ids, |b, ids| {
|
||||
group.bench_with_input(
|
||||
BenchmarkId::new("HashMap (hashbrown)", size),
|
||||
&search_ids,
|
||||
|b, ids| {
|
||||
b.iter(|| {
|
||||
for &id in ids {
|
||||
black_box(bench_hashbrown_search(&hashbrown, black_box(id)));
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
group.bench_with_input(BenchmarkId::new("FxHashMap", size), &search_ids, |b, ids| {
|
||||
group.bench_with_input(
|
||||
BenchmarkId::new("FxHashMap", size),
|
||||
&search_ids,
|
||||
|b, ids| {
|
||||
b.iter(|| {
|
||||
for &id in ids {
|
||||
black_box(bench_fxhashmap_search(&fxhashmap, black_box(id)));
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
group.finish();
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use std::cmp::Ordering;
|
||||
use crate::app::AppState;
|
||||
use crate::core::srs::{FADE_PER_DAY, MAX_SCORE, OrderMode, WordOpenMode};
|
||||
use crate::data::{INVALID_ID, Id};
|
||||
@@ -7,6 +6,7 @@ use chrono::{DateTime, Utc};
|
||||
use log::info;
|
||||
use rayon::prelude::*;
|
||||
use rhai::{Engine, Scope};
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::HashMap;
|
||||
use std::marker::PhantomData;
|
||||
use std::time::Instant;
|
||||
@@ -184,7 +184,6 @@ pub struct EntityHandle<E> {
|
||||
pub(crate) id: Id,
|
||||
index: i32,
|
||||
pub(crate) _phantom: PhantomData<E>,
|
||||
|
||||
}
|
||||
|
||||
impl<T> Clone for EntityHandle<T> {
|
||||
@@ -201,7 +200,7 @@ impl<T> EntityHandle<T> {
|
||||
Self {
|
||||
id,
|
||||
index: index as i32 | (!real as i32) << 31,
|
||||
_phantom: Default::default()
|
||||
_phantom: Default::default(),
|
||||
}
|
||||
}
|
||||
pub fn index(&self) -> usize {
|
||||
@@ -236,11 +235,11 @@ impl<T> PartialOrd<Self> for EntityHandle<T> {
|
||||
impl<T> Ord for EntityHandle<T> {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
if self.real() && !other.real() {
|
||||
return Ordering::Less
|
||||
return Ordering::Less;
|
||||
}
|
||||
|
||||
if !self.real() && other.real() {
|
||||
return Ordering::Greater
|
||||
return Ordering::Greater;
|
||||
}
|
||||
|
||||
self.id.cmp(&other.id)
|
||||
|
||||
@@ -98,7 +98,7 @@ where
|
||||
rule: Box<dyn Fn(&T) -> bool + Send + Sync>,
|
||||
parallel: bool,
|
||||
_marker: PhantomData<(R, D)>,
|
||||
shift_stamp: u16
|
||||
shift_stamp: u16,
|
||||
}
|
||||
|
||||
impl<T: EntityData + Clone, R: Repository<T, D>, D: DbLayer<T>> Query<T, R, D> {
|
||||
@@ -177,8 +177,8 @@ pub trait BatchedDbLayer<T>
|
||||
where
|
||||
T: EntityData,
|
||||
{
|
||||
fn delete_many(&mut self, ids: &[Id], connection: &Connection) -> MaybeError;
|
||||
fn add_many_entity(&mut self, entity: &mut [T], connection: &Connection) -> MaybeError;
|
||||
fn delete_many_entities(&mut self, ids: &[Id], connection: &Connection) -> MaybeError;
|
||||
fn add_many_entities(&mut self, entity: &mut [T], connection: &Connection) -> MaybeError;
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -405,7 +405,7 @@ impl<T: EntityData + Clone, D: BatchedDbLayer<T> + DbLayer<T>> BatchedRepository
|
||||
});
|
||||
|
||||
self.data_layer
|
||||
.add_many_entity(&mut temp_values, &self.connection.read())?;
|
||||
.add_many_entities(&mut temp_values, &self.connection.read())?;
|
||||
|
||||
let start = self.cache.len();
|
||||
|
||||
@@ -447,7 +447,7 @@ impl<T: EntityData + Clone, D: BatchedDbLayer<T> + DbLayer<T>> BatchedRepository
|
||||
!remove
|
||||
});
|
||||
self.data_layer
|
||||
.delete_many(cached.as_slice(), &self.connection.read())?;
|
||||
.delete_many_entities(cached.as_slice(), &self.connection.read())?;
|
||||
let len = cached.len();
|
||||
cell = 0;
|
||||
self.cache.retain(|x| {
|
||||
|
||||
Reference in new issue
Block a user