# 编程语言EF速度测试(1)：spectral-norm

import 工具;

//spectral-norm
public class 启动类 <作者 = "liigo">
{
private static double eval_A(int i, int j) { return 1.0/((i+j)*(i+j+1)/2+i+1); }

private static eval_A_times_u(int N, double[] u, double[] Au)
{
int i,j;
for(i=0;i<N;i++)
{
Au[i]=0;
for(j=0;j<N;j++) Au[i]+=eval_A(i,j)*u[j];
}
}

private static eval_At_times_u(int N, double[] u, double[] Au)
{
int i,j;
for(i=0;i<N;i++)
{
Au[i]=0;
for(j=0;j<N;j++) Au[i]+=eval_A(j,i)*u[j];
}
}

private static eval_AtA_times_u(int N, double[] u, double[] AtAu)
{ double[] v = new double[N]; eval_A_times_u(N,u,v); eval_At_times_u(N,v,AtAu); }

public static  main(string[] args)
{
int time = 运行环境.取启动时间();
int i;
int N = 5500;
double[] u = new double[N], v = new double[N];
double vBv, vv;

for(i=0;i<N;i++) u[i]=1;

for(i=0;i<10;i++)
{
eval_AtA_times_u(N,u,v);
eval_AtA_times_u(N,v,u);
}

vBv=0; vv=0;
for(i=0;i<N;i++) { vBv+=u[i]*v[i]; vv+=v[i]*v[i]; }

控制台.输出行(工具.数学运算.求平方根(vBv/vv));
控制台.输出行("time(ms): ", 运行环境.取启动时间() - time);
控制台.输入文本();
}
}