Commit c87a3333 authored by Pierre Donat-Bouillud's avatar Pierre Donat-Bouillud
Browse files

Benchmarking effects with criterion

parent 8404646e
Pipeline #709 passed with stage
in 2 minutes and 55 seconds
This diff is collapsed.
......@@ -26,7 +26,7 @@ name = "audio_adaptive"
libc = "0.2.11"
rustbox = "*"
portaudio = "*"
rand = "0.5"
rand = "*"
time = "*"
lazy_static = "*"
#ncollide = "0.9.0"
......@@ -37,3 +37,10 @@ pest_derive = "2.0"
itertools = "*"
crossbeam-channel = "*"
clap = "*"
[dev-dependencies]
criterion = "0.2.9"
[[bench]]
name = "effect_benchmark"
harness = false
#[macro_use]
extern crate criterion;
use criterion::*;
extern crate audio_adaptive;
use audio_adaptive::audiograph::*;
use audio_adaptive::samplerate;
fn osc_bench(c : &mut Criterion) {
c.bench_function("osc", |b| {
let mut osc = Oscillator::new(0., 440, 1.);
let input = vec![DspEdge::new(1, 1, 256, 44100);1];
b.iter( ||
{
let mut output = vec![DspEdge::new(1, 1, 256, 44100);1];
osc.process(&input, &mut output)}
)});
}
fn mod_bench(c : &mut Criterion) {
c.bench_function("mod", |b| {
let mut modu = Modulator::new(0., 440, 1.);
let input = vec![DspEdge::new(1, 1, 256, 44100);1];
b.iter( ||
{
let mut output = vec![DspEdge::new(1, 1, 256, 44100);1];
modu.process(&input, &mut output)}
)});
}
fn resampler_bench(c : &mut Criterion) {
let parameters = vec![samplerate::ConverterType::SincBestQuality, samplerate::ConverterType::SincMediumQuality,
samplerate::ConverterType::SincFastest, samplerate::ConverterType::ZeroOrderHold,
samplerate::ConverterType::Linear];
c.bench(
"resampler",
ParameterizedBenchmark::new(
"my_function",
move |b, conv_type| {
let mut conv = Resampler::new(conv_type.clone(), 0.5);
let input = vec![DspEdge::new(1, 1, 256, 44100);1];
b.iter(|| {
let mut output = vec![DspEdge::new(1, 1, 128, 44100);1];
conv.process(&input, &mut output)
})},
parameters
)
);
}
criterion_group!(benches, osc_bench, mod_bench, resampler_bench);
criterion_main!(benches);
......@@ -17,6 +17,7 @@ use std::fmt;
use audiograph_parser;
use samplerate;
#[derive(Debug)]
pub enum AudioGraphError {
Cycle,
......@@ -592,7 +593,7 @@ fn sine_wave(phase : f32, volume : f32) -> f32 {
}
#[derive(Debug)]
struct Oscillator {
pub struct Oscillator {
phase: f32,
frequency: u32,
volume: f32
......@@ -634,7 +635,7 @@ impl AudioEffect for Oscillator {
}
#[derive(Debug)]
struct Modulator {
pub struct Modulator {
phase: f32,
frequency: u32,
volume: f32
......
......@@ -30,7 +30,7 @@ use audio_adaptive::sndfile;
const CHANNELS: i32 = 1;
const SAMPLE_RATE: u32 = 44_100;
const NB_CYCLES : u32 = 12000;
const FRAMES_PER_BUFFER : usize = 64;
const FRAMES_PER_BUFFER : usize = 256;
#[derive(Clone, Copy, Debug)]
pub struct TimeMonitor {
......
......@@ -16,7 +16,8 @@ use std::thread;
use std::time as rust_time;//To be used for thread::sleep for instance
use std::process::exit;
use rand::Rng;
use rand::prelude::*;
use rand::seq::SliceRandom;
use std::io::prelude::*;
use std::fs::File;
......@@ -62,11 +63,11 @@ fn run(mode : Mode, nb_oscillators : u32, proba_edge : f64) -> Result<(), pa::Er
let mut audio_graph = rand_gen.generate(& |c, rng|
{
let generators = vec![DspNode::Modulator(5., 500 + rng.gen_range::<u32>(0, 400), 1.0),
DspNode::LowPass([5.,6.,7.,8.],200. + rng.gen_range::<f32>(0., 400.),0.8)];
let generators = vec![DspNode::Modulator(5., 500 + rng.gen_range(0, 400), 1.0),
DspNode::LowPass([5.,6.,7.,8.],200. + rng.gen_range(0., 400.),0.8)];
match c {
NodeClass::Input => DspNode::Oscillator(6., 500 + rng.gen_range::<u32>(0, 400), 1.0),
NodeClass::Transformer | NodeClass::Output => *rng.choose(&generators).unwrap()
NodeClass::Input => DspNode::Oscillator(6., 500 + rng.gen_range(0, 400), 1.0),
NodeClass::Transformer | NodeClass::Output => *generators.choose(rng).unwrap()
}
});
//TODO: don't generate cyclic graphs!!
......
//! To generate random acyclic directed graphs
//! with random effects and test the adaptive scheduling algorithm on it
use rand::{Rng,SeedableRng, StdRng, thread_rng, ThreadRng};
//use rand::{Rng,SeedableRng, StdRng, thread_rng, ThreadRng};
use rand::prelude::*;
use std::hash::Hash;
use effect::*;
......
......@@ -19,7 +19,7 @@ struct src_data {
src_ratio: c_double,
}
#[derive(Debug)]
#[derive(Debug, Clone)]
#[repr(C)]
pub enum ConverterType {
SincBestQuality,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment