为了保证效果,与java操作相同,先清除一下垃圾C#的用法是:【GC.Collect()】
代码语言:javascript
复制using System;
using System.Diagnostics;
namespace Action
{
class Program
{
static void Main(string[] args)
{
GC.Collect();//清理一下先
Random ra = new Random();
int count = 1000000;//100W
DateTime start = DateTime.Now;
for (int i = 0; i < count; i )
{
new String("" i);
}
DateTime end = DateTime.Now;
double usedMemory = Process.GetCurrentProcess().WorkingSet64 / 1024.0 / 1024.0;
Console.WriteLine("耗时:" (end - start).TotalMilliseconds "毫秒");
Console.WriteLine("消耗内存:" usedMemory "M");
}
}
}
做接口的时候一定好好测好了再上线,否则接口突然的来一个"刷子"就够你抢。