2024年4月30日发(作者:)

我编了段程序测试它的性能:

int[] source = new int[100000];

Random random = new Random();

for (int i = 0; i < ; i++)

{

source[i] = (100);

}

int sum=0;

long start = unt;

for (int time = 0; time < 1000; time++)

{

sum = 0;

foreach (int v in source)

{

sum += v;

}

}

long cost = unt - start;

ine("MSIL result={0};cost={1}", sum, cost);

start = unt;

for (int time = 0; time < 1000; time++)

{

sum = 0;

fixed(int* pstart = source, pend = &source[-1])

{

for (int* pnow=pstart; pnow < pend; pnow++)

{

sum += *pnow;

}

}

}

cost = unt - start;

ine("CSP result={0};cost={1}", sum, cost);

fixed (int* point = source)

{

start = unt;

for (int time = 0; time < 1000; time++)

{

sum = CalArray(point, );

}

cost = unt - start;

ine("MASM result={0};cost={1}",sum,cost);

}