Skip to content

Commit

Permalink
Merge pull request #398 from adriencaccia/fix/benchmark-load-data
Browse files Browse the repository at this point in the history
Make benchmarks work again
  • Loading branch information
Ogeon authored May 1, 2024
2 parents 43ff0a6 + ac02f53 commit 148f406
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
1 change: 0 additions & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ jobs:
uses: CodSpeedHQ/action@v2
with:
run: cargo codspeed run
working-directory: integration_tests # mimics how tests work, so the colors CSV can be found
token: ${{ secrets.CODSPEED_TOKEN }}
6 changes: 4 additions & 2 deletions benchmarks/benches/cie.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::path::Path;

use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Criterion};
use palette::{
color_difference::{Ciede2000, DeltaE, ImprovedDeltaE},
Expand All @@ -22,7 +24,7 @@ use data_color_mine::{load_data, ColorMine};

fn cie_conversion(c: &mut Criterion) {
let mut group = c.benchmark_group("Cie family");
let mut colormine: Vec<ColorMine<f32>> = load_data();
let mut colormine: Vec<ColorMine<f32>> = load_data(Some(Path::new("../integration_tests/tests/convert/data_color_mine.csv")));
colormine.truncate(colormine.len() - colormine.len() % 8);
assert_eq!(
colormine.len() % 8,
Expand Down Expand Up @@ -121,7 +123,7 @@ fn cie_conversion(c: &mut Criterion) {

fn cie_delta_e(c: &mut Criterion) {
let mut group = c.benchmark_group("Cie delta E");
let colormine: Vec<ColorMine<f32>> = load_data();
let colormine: Vec<ColorMine<f32>> = load_data(Some(Path::new("../integration_tests/tests/convert/data_color_mine.csv")));

let lab: Vec<Lab> = colormine
.iter()
Expand Down
4 changes: 3 additions & 1 deletion benchmarks/benches/rgb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::path::Path;

use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Criterion};
use palette::convert::FromColorUnclamped;
use palette::encoding;
Expand Down Expand Up @@ -39,7 +41,7 @@ use data_color_mine::{load_data, ColorMine};

fn rgb_conversion(c: &mut Criterion) {
let mut group = c.benchmark_group("Rgb family");
let mut colormine: Vec<ColorMine<f32>> = load_data();
let mut colormine: Vec<ColorMine<f32>> = load_data(Some(Path::new("../integration_tests/tests/convert/data_color_mine.csv")));
colormine.truncate(colormine.len() - colormine.len() % 8);
assert_eq!(
colormine.len() % 8,
Expand Down
12 changes: 8 additions & 4 deletions integration_tests/tests/convert/data_color_mine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
List of color from www.colormine.org
*/

use std::path::Path;

use approx::assert_relative_eq;
use lazy_static::lazy_static;
use serde_derive::Deserialize;
Expand Down Expand Up @@ -318,16 +320,18 @@ where
}

lazy_static! {
static ref TEST_DATA: Vec<ColorMine<f64>> = load_data();
static ref TEST_DATA: Vec<ColorMine<f64>> = load_data(None);
}

pub fn load_data<F>() -> Vec<ColorMine<F>>
pub fn load_data<F>(data_path: Option<&Path>) -> Vec<ColorMine<F>>
where
F: for<'a> serde::Deserialize<'a>,
ColorMineRaw<F>: Into<ColorMine<F>>,
{
let mut rdr = csv::Reader::from_path("tests/convert/data_color_mine.csv")
.expect("csv file could not be loaded in tests for color mine data");
let mut rdr = csv::Reader::from_path(
data_path.unwrap_or_else(|| Path::new("tests/convert/data_color_mine.csv")),
)
.expect("csv file could not be loaded in tests for color mine data");
let mut color_data: Vec<ColorMine<F>> = Vec::new();
for record in rdr.deserialize() {
let r: ColorMineRaw<F> =
Expand Down

0 comments on commit 148f406

Please sign in to comment.