Skip to content

Commit

Permalink
migrate to Vite+TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
iahu committed Dec 13, 2024
1 parent 7985897 commit 6f8b998
Show file tree
Hide file tree
Showing 17 changed files with 1,087 additions and 708 deletions.
26 changes: 0 additions & 26 deletions .eslintrc.js

This file was deleted.

20 changes: 20 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"root": true,
"env": { "browser": true, "es2020": true },
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"ignorePatterns": ["dist", ".eslintrc.js", ".prettierrc.js"],
"parser": "@typescript-eslint/parser",
"rules": {
"indent": ["error", 2],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"semi": ["error", "always"],
"no-var": ["off"]
},
"ignorePatterns": ["**/node_modules/", ".eslintrc.json", "/dist/*"],
"settings": {
"react": {
"version": "detect"
}
}
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ npm-debug.log
*.log
*.pdf
*.gz
*.lock
.DS_Store
package-lock.json
*.lock
54 changes: 26 additions & 28 deletions bench/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
'use strict';
import FFT from '../dist/fft.js';
import jensnockert from 'fft';
import dspjs from 'dsp.js';
import drom from 'fourier';
import fourierTransform from 'fourier-transform';
import benchmark from 'benchmark';

const FFT = require('../');
const external = {
jensnockert: require('fft'),
dspjs: require('dsp.js'),
drom: require('fourier'),
fourierTransform: require('fourier-transform')
jensnockert,
dspjs,
drom,
fourierTransform,
};
const benchmark = require('benchmark');

function regexFilter(value) {
if (value !== undefined && value.length !== 0)
return new RegExp(value, 'ig');
else
return /./g;
if (value !== undefined && value.length !== 0) return new RegExp(value, 'ig');
else return /./g;
}

/*eslint-disable no-undef */
Expand All @@ -22,16 +23,14 @@ const filter1 = regexFilter(process.argv[3]);
/*eslint-enable no-undef */

function addFiltered(suite, name, body) {
if (name.match(filter1) === null)
return;
if (name.match(filter1) === null) return;

suite.add(name, body);
}

function createInput(size) {
const res = new Array(size);
for (let i = 0; i < res.length; i++)
res[i] = Math.random() * 2 - 1;
for (let i = 0; i < res.length; i++) res[i] = Math.random() * 2 - 1;
return res;
}

Expand All @@ -49,10 +48,9 @@ function addSelf(suite, size) {
const f = new FFT(size);
const input = createInput(f.size);
const data = f.toComplexArray(input);
const out = f.createComplexArray();

addFiltered(suite, 'fft.js', () => {
f.transform(out, data);
f.transform(data);
});
}

Expand Down Expand Up @@ -84,7 +82,7 @@ function addDrom(suite, size) {
const stdlib = {
Math: Math,
Float32Array: Float32Array,
Float64Array: Float64Array
Float64Array: Float64Array,
};
const f = new external.drom.custom[`fft_f64_${size}_asm`](stdlib, null, heap);

Expand All @@ -110,10 +108,9 @@ function addRealSelf(suite, size) {
const f = new FFT(size);
const input = createInput(f.size);
const data = f.toComplexArray(input);
const out = f.createComplexArray();

addFiltered(suite, 'fft.js', () => {
f.realTransform(out, data);
f.realTransform(data);
});
}

Expand Down Expand Up @@ -147,18 +144,19 @@ const benchmarks = [
{ title: 'realTransform size=2048', suite: realTransform(2048) },
{ title: 'realTransform size=4096', suite: realTransform(4096) },
{ title: 'realTransform size=8192', suite: realTransform(8192) },
{ title: 'realTransform size=16384', suite: realTransform(16384) }
{ title: 'realTransform size=16384', suite: realTransform(16384) },
];

/* eslint-disable no-console */
benchmarks.forEach((bench) => {
if (bench.title.match(filter0) === null)
return;
if (bench.title.match(filter0) === null) return;
console.log('===== %s =====', bench.title);
bench.suite.on('cycle', (event) => {
console.log(' '+ String(event.target));
}).on('complete', function() {
console.log(' Fastest is ' + this.filter('fastest').map('name'));
});
bench.suite
.on('cycle', (event) => {
console.log(' ' + String(event.target));
})
.on('complete', function () {
console.log(' Fastest is ' + this.filter('fastest').map('name'));
});
bench.suite.run();
});
1 change: 1 addition & 0 deletions bench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"private": true,
"description": "Benchmarks for fft.js",
"type": "module",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down
13 changes: 13 additions & 0 deletions dist/fft.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default class FFT {
#private;
size: number;
table: number[];
constructor(size: number);
fromComplexArray(complex: number[]): number[];
createComplexArray(): number[];
toComplexArray(input: number[]): number[];
completeSpectrum(spectrum: number[]): number[];
transform(data: number[]): number[];
realTransform(data: number[]): number[];
inverseTransform(data: number[]): number[];
}
Loading

0 comments on commit 6f8b998

Please sign in to comment.