欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

C#、PHP与NodeJs性能测试对比

程序员文章站 2022-05-29 16:22:00
...

namespace Benchmark { using System ; using System.Web ; using System.Web.UI ; using System.Threading.Tasks ; public partial class Default : System. Web . UI . Page { Randomrnd = null ; public void Page_Load ( object sender,EventArgse ) { /

namespace Benchmark

{

using System;

using System.Web;

using System.Web.UI;

using System.Threading.Tasks;

public partial class Default : System.Web.UI.Page

{

Random rnd=null;

public void Page_Load(object sender, EventArgs e)

{

//RegisterAsyncTask(new PageAsyncTask(PerformIOasync,PerformIOasync,null,null));

rnd = new Random ();

//Task.Run (new Action (PerformIOasync));

PerformIOasync ();

}

public async void PerformIOasync()

{

string s=""; //generate a random string of 108KB and a random filename

string fname = rndchar() + rndchar() + rndchar() + rndchar() +".txt";

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

{

char ch=rndchar();

s += ch;

}

//write s to a file

//file_put_contents($fname,$s);

var slowTask1 = Taskstring>.Factory.StartNew(()=> WriteToDisk(fname,s));

await slowTask1;

var SlowTask2 = Taskstring>.Factory.StartNew(()=> ReadFromDisk(fname,s));

await SlowTask2;

Response.Write(SlowTask2.Result.ToString());

}

private string WriteToDisk(string fname, string s){

System.IO.File.WriteAllText (AppDomain.CurrentDomain.BaseDirectory + fname, s);

return "";

}

private string ReadFromDisk(string fname, string s){

return System.IO.File.ReadAllText (AppDomain.CurrentDomain.BaseDirectory + fname);

}

private char rndchar()

{

return (char)rnd.Next (65, 112);

}

}

}