Coder Social home page Coder Social logo

fftbench's Introduction

Optimizing with C++11 templates

This code demonstrates using recursive C++11 templates to improve performance of the Cooley-Tukey algorithm for FFT. First, the classical code is updated to use basic C++11 features. This makes things simpler and easier to understand. Next, we convert the looping structure into a recursive template. Finally, we upgrade from radix 2 to radix 4 and apply various optimizations.

  • four1.hpp - Classical implementation using loops.
  • four1plus.hpp - Like four1 but using std::array and std::complex.
  • four1tmpl.hpp - Improved four1 using template recursion.
  • fft.hpp - Radix 4 version with lots of optimizations.

C++11 compilers use ISO rules for std::complex multiplication and division. The extra checking for (nan,nan) results cause a significant performance problem. Because this is not needed for DSP applications, the multiplication and division operators in ::std can be replaced with limited range versions. This is done to ease the development process and becomes unnecessary in the final fft.hpp code which uses its own multiply() method.

  • cxlr.hpp - Changes std::complex multiplication.

Everything is included in this repository and there is only one file to compile. No makefile is used, simply compile and run with:

g++ -o bench -std=c++11 -O3 main.cpp && ./bench

Example output from GCC 4.9:

[ RUN      ] FFTfixture<float>.four1
[   TIME   ] 27 iterations, 504.25 us
[       OK ] FFTfixture<float>.four1 (13 ms)
[ RUN      ] FFTfixture<float>.four1plus
[   TIME   ] 21 iterations, 504.75 us
[       OK ] FFTfixture<float>.four1plus (10 ms)
[ RUN      ] FFTfixture<float>.four1tmpl
[   TIME   ] 22 iterations, 324.333 us
[       OK ] FFTfixture<float>.four1tmpl (11 ms)
[ RUN      ] FFTfixture<float>.fft
[   TIME   ] 24 iterations, 132.167 us
[       OK ] FFTfixture<float>.fft (8 ms)

License

This project is designed as an educational tool to demonstrate a method for optimizing algorithms in C++11. Some of the code, particularly the four1.hpp example, is presented here under fair use. Depending on how you plan to use this project, you may be required to obtain permission with the following two exceptions:

The benchtest library is a snapshot from my dspp project. If you want to try it in your project, it is best to get from there: https://github.com/AE9RB/dspp

The fft.hpp file is MIT licensed. License and documentation are in the file. Simply copy it to your project. It has no dependencies.

fftbench's People

Contributors

ae9rb avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

hansvi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.