double inputData = new double[arrayLength]; // ... 给inputData赋值 FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD); Complex[] result = fft.transform(inputData, TransformType.FORWARD);
import org.apache.commons.math3.transform.DftNormalization;
import org.apache.commons.math3.transform.FastFourierTransformer;
import org.apache.commons.math3.transform.TransformType;
interface TestCase
{
public Object run(List<Object> params) throws Exception;
public List<Object> getParams();
}
class CalcFFT implements TestCase
{
public CalcFFT()
{
System.out.print("本算例用于计算快速傅立叶变换。正在初始化 计算数据(" + arrayLength + "点)... ...");
inputData = new double[arrayLength];
for (int index = 0; index < inputData.length; index++)
{
inputData[index] = (Math.random() - 0.5) * 100.0;
}
System.out.println("初始化完成");
}
@Override
public List<Object> getParams()
{
return null;
}
@Override
public Object run(List<Object> params) throws Exception
{
FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD);
Complex[] result = fft.transform(inputData, TransformType.FORWARD);
return result;
}
private double[] inputData = null;
private final int arrayLength = 4 * 1024*1024;
}
public class TimeCostCalculator
{
public TimeCostCalculator()
{
}
/**
* 计算指定对象的运行时间开销。
*
* @param testCase 指定被测对象。
* @return 返回sub.run的时间开销,单位为s。
* @throws Exception
*/
public double calcTimeCost(TestCase testCase) throws Exception
{
List<Object> params = testCase.getParams();
long startTime = System.nanoTime();
testCase.run(params);
long stopTime = System.nanoTime();
System.out.println("start: " + startTime + " / stop: " + stopTime);
double timeCost = (stopTime - startTime) * 1.0e-9;
// double timeCost = BigDecimal.valueOf(stopTime - startTime, 9).doubleValue();
return timeCost;
}
public static void main(String[] args) throws Exception
{
TimeCostCalculator tcc = new TimeCostCalculator();
double timeCost;
System.out.println("--------------------------------------------------------------------------");
timeCost = tcc.calcTimeCost(new CalcFFT());
System.out.println("time cost is: " + timeCost + "s");
System.out.println("--------------------------------------------------------------------------");
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有