automatica 0.10.1

Automatic control systems library
Documentation
//#[macro_use]
extern crate automatica;

use std::time::Instant;

use crate::automatica::Poly;

fn main() {
    println!("Loss of precision multiplication");
    let (convolution, fft) = bench_1();
    println!("Convolution: {} µs, fft: {} µs", convolution, fft);

    println!("20th degree multiplication");
    let (convolution2, fft2) = bench_2();
    println!("Convolution: {} µs, fft: {} µs", convolution2, fft2);

    println!("100th degree multiplication");
    let (convolution3, fft3) = bench_3();
    println!("Convolution: {} µs, fft: {} µs", convolution3, fft3);
}

fn bench_1() -> (u128, u128) {
    let wp = Poly::new_from_roots(&[1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.]);

    let start = Instant::now();
    let result = &wp * ℘
    let first_step = start.elapsed().as_micros();
    println!("{:.1e}", result);

    let wp2 = wp.clone();

    let later = Instant::now();
    let result2 = wp.mul_fft(wp2);
    let second_step = later.elapsed().as_micros();
    println!("{:.1e}", result2);
    (first_step, second_step)
}

fn bench_2() -> (u128, u128) {
    // points = [[1:20],zeros(1,44)]; res=ifft(fft(points)^2); res(1:39)
    let wp = Poly::new_from_coeffs(&[
        1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20.,
    ]);

    let start = Instant::now();
    let result = &wp * &wp * ℘
    let first_step = start.elapsed().as_micros();
    println!("{:.1e}", result);

    let wp2 = wp.clone();
    let wp3 = wp.clone();

    let later = Instant::now();
    let result2 = wp.mul_fft(wp2).mul_fft(wp3);
    let second_step = later.elapsed().as_micros();
    println!("{:.1e}", result2);

    (first_step, second_step)
}

fn bench_3() -> (u128, u128) {
    let wp = Poly::new_from_coeffs_iter(std::iter::repeat(2.0).take(100));

    let start = Instant::now();
    let result = &wp * ℘
    let first_step = start.elapsed().as_micros();
    println!("{:.1e}", result);

    let wp2 = wp.clone();

    let later = Instant::now();
    let result2 = wp.mul_fft(wp2);
    let second_step = later.elapsed().as_micros();
    println!("{:.1e}", result2);

    (first_step, second_step)
}