public Form1()
{
InitializeComponent();
Stopwatch sw = new Stopwatch();
sw.Start();
//string filePath = @"D:\cp.bin";
string filePath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"cp.txt";//设置路径将文件保存在目标文件下
using (FileStream fs = File.Create(filePath))//优化
{
double t0 = 0, f0 = 100000d;
//double beta = (f1 - f0) / t1;
double beta = 900000d/4.194304d;
double chirp = 0;
for(int i=0; i<=167772160; i++)
{
t0 += 0.000000025;
chirp = Math.Cos(Math.PI * (2 * f0 + beta * t0) * t0);
chirp = Math.Round(chirp * 2046);
chirp = chirp*2 + 2046;
byte[] b=Encoding.Unicode.GetBytes(chirp.ToString());
fs.Write(b, 0, b.Length);
}
}
sw.Stop();
MessageBox.Show("耗时为: " + sw.ElapsedMilliseconds.ToString() + " ms");
}