mirror of
https://github.com/ankitects/anki.git
synced 2026-01-13 22:13:58 -05:00
Do DR calculation in parallel
Approx 5x faster on my machine
This commit is contained in:
parent
06e17dff11
commit
d90e2c717c
5 changed files with 10 additions and 0 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -131,6 +131,7 @@ dependencies = [
|
||||||
"prost-reflect",
|
"prost-reflect",
|
||||||
"pulldown-cmark 0.13.0",
|
"pulldown-cmark 0.13.0",
|
||||||
"rand 0.9.1",
|
"rand 0.9.1",
|
||||||
|
"rayon",
|
||||||
"regex",
|
"regex",
|
||||||
"reqwest 0.12.20",
|
"reqwest 0.12.20",
|
||||||
"rusqlite",
|
"rusqlite",
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,7 @@ prost-types = "0.13"
|
||||||
pulldown-cmark = "0.13.0"
|
pulldown-cmark = "0.13.0"
|
||||||
pyo3 = { version = "0.25.1", features = ["extension-module", "abi3", "abi3-py39"] }
|
pyo3 = { version = "0.25.1", features = ["extension-module", "abi3", "abi3-py39"] }
|
||||||
rand = "0.9.1"
|
rand = "0.9.1"
|
||||||
|
rayon = "1.10.0"
|
||||||
regex = "1.11.1"
|
regex = "1.11.1"
|
||||||
reqwest = { version = "0.12.20", default-features = false, features = ["json", "socks", "stream", "multipart"] }
|
reqwest = { version = "0.12.20", default-features = false, features = ["json", "socks", "stream", "multipart"] }
|
||||||
rusqlite = { version = "0.36.0", features = ["trace", "functions", "collation", "bundled"] }
|
rusqlite = { version = "0.36.0", features = ["trace", "functions", "collation", "bundled"] }
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,7 @@ pin-project.workspace = true
|
||||||
prost.workspace = true
|
prost.workspace = true
|
||||||
pulldown-cmark.workspace = true
|
pulldown-cmark.workspace = true
|
||||||
rand.workspace = true
|
rand.workspace = true
|
||||||
|
rayon.workspace = true
|
||||||
regex.workspace = true
|
regex.workspace = true
|
||||||
reqwest.workspace = true
|
reqwest.workspace = true
|
||||||
rusqlite.workspace = true
|
rusqlite.workspace = true
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ use fsrs::FSRS;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use rand::rngs::StdRng;
|
use rand::rngs::StdRng;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
use rayon::iter::IntoParallelIterator;
|
||||||
|
use rayon::iter::ParallelIterator;
|
||||||
|
|
||||||
use crate::card::CardQueue;
|
use crate::card::CardQueue;
|
||||||
use crate::card::CardType;
|
use crate::card::CardType;
|
||||||
|
|
@ -276,6 +278,7 @@ impl Collection {
|
||||||
) -> Result<SimulateFsrsWorkloadResponse> {
|
) -> Result<SimulateFsrsWorkloadResponse> {
|
||||||
let (config, cards) = self.simulate_request_to_config(&req)?;
|
let (config, cards) = self.simulate_request_to_config(&req)?;
|
||||||
let dr_workload = (70u32..=99u32)
|
let dr_workload = (70u32..=99u32)
|
||||||
|
.into_par_iter()
|
||||||
.map(|dr| {
|
.map(|dr| {
|
||||||
let result = simulate(
|
let result = simulate(
|
||||||
&config,
|
&config,
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,10 @@ impl TimestampMillis {
|
||||||
pub fn adding_secs(self, secs: i64) -> Self {
|
pub fn adding_secs(self, secs: i64) -> Self {
|
||||||
Self(self.0 + secs * 1000)
|
Self(self.0 + secs * 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn elapsed_millis(self) -> u64 {
|
||||||
|
(Self::now().0 - self.0).max(0) as u64
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn elapsed() -> time::Duration {
|
fn elapsed() -> time::Duration {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue