Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tigerros committed Aug 10, 2024
1 parent 2d0f6ab commit 6fd0730
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 236 deletions.
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ proptest = "1.4.0"
criterion = "0.5.1"

[[bench]]
name = "benches"
name = "variation"
harness = false

[features]
samples = []
[[bench]]
name = "pgn"
harness = false
73 changes: 0 additions & 73 deletions benches/benches.rs

This file was deleted.

8 changes: 4 additions & 4 deletions benches/pgn.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use rpgn::pgn::samples::*;
use rpgn::{Pgn, Turn};
use rpgn::samples::pgn_samples;
use rpgn::Pgn;

pub fn to_pgn(c: &mut Criterion) {
let mut group = c.benchmark_group("to_pgn");

for pgn in samples().iter().filter_map(|s| s.parsed.as_ref().ok()) {
for pgn in pgn_samples().iter().filter_map(|s| s.parsed.as_ref().ok()) {
let turns = pgn.root_variation.as_ref().unwrap().turns();
let mut id = String::with_capacity(5 * 2 + 1);

Expand All @@ -24,7 +24,7 @@ pub fn to_pgn(c: &mut Criterion) {
pub fn from_pgn(c: &mut Criterion) {
let mut group = c.benchmark_group("from_pgn");

for (pgn_string, pgn) in samples()
for (pgn_string, pgn) in pgn_samples()
.iter()
.filter_map(|s| s.parsed.as_ref().ok().map(|p| (s.string, p)))
{
Expand Down
24 changes: 14 additions & 10 deletions benches/variation.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, black_box};
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
use rpgn::samples::*;
use rpgn::{Pgn, Turn};

pub fn construct(c: &mut Criterion) {
let mut group = c.benchmark_group("construct");

for var in variation_sample_fns() {
let turns = var().turns();
let mut id = String::with_capacity(4 * 2 + 1);
Expand All @@ -17,7 +17,7 @@ pub fn construct(c: &mut Criterion) {
b.iter(|| black_box(var()))
});
}

group.finish()
}

Expand All @@ -33,13 +33,17 @@ pub fn read_positions(c: &mut Criterion) {
id.push('-');
id.push_str(&turns.last().unwrap().r#move().to_string().replace('-', ""));

group.bench_with_input(BenchmarkId::from_parameter(id), &(turns, var), |b, (turns, var)| {
b.iter(|| {
for i in 0..turns.len() {
let _ = var.get_position(i);
}
})
});
group.bench_with_input(
BenchmarkId::from_parameter(id),
&(turns, var),
|b, (turns, var)| {
b.iter(|| {
for i in 0..turns.len() {
let _ = var.get_position(i);
}
})
},
);
}

group.finish();
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@ dry_mods::mods! {
time_control_field;
pub mod pgn;
}
#[cfg(feature = "samples")]
pub mod samples;
pub use pgn::{Pgn, PgnParseError};
1 change: 0 additions & 1 deletion src/pgn/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mod visitor;
pub use visitor::PgnSanError;
dry_mods::mods! {
mod pub use pgn,
date,
Expand Down
2 changes: 1 addition & 1 deletion src/pgn/pgn.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::{Display, Formatter, Write};
use std::io::Read;
use pgn_reader::BufferedReader;
use super::visitor::{Visitor, PgnSanError};
use super::visitor::Visitor;
use crate::{Eco, pgn::{Outcome, Date, Round}, Variation, VariationSanPlayError};

#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down
2 changes: 1 addition & 1 deletion src/pgn/visitor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use pgn_reader::{RawHeader, Skip};
use std::str::FromStr;
use shakmaty::Chess;
use shakmaty::san::{SanError, SanPlus};
use shakmaty::san::SanPlus;
use crate::{Variation, Eco, pgn::{Date, Round, Outcome, Pgn}, TurnsCapacity, VariationsCapacity, VariationSanPlayError};

pub(super) struct Visitor {
Expand Down
Loading

0 comments on commit 6fd0730

Please # to comment.