C#、PHP与NodeJs性能测试对比
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);
}
}
}
推荐阅读
-
i7-7740X和i7-7700K的区别是什么 i7-7740X与i7-7700K性能对比测试图解
-
php中随机函数mt_rand()与rand()性能对比分析
-
php中serialize序列化与json性能测试的示例分析
-
PHP中strtr与str_replace函数运行性能简单测试示例
-
PHP中fwrite与file_put_contents性能测试代码
-
类与结构体性能对比测试——以封装网络心跳包为例
-
PHP性能测试工具xhprof安装与使用方法详解
-
JSP与PHP性能测试对比
-
PHP4和PHP5性能测试和对比 测试代码与环境
-
关于PHP7.0与PHP5.6下Laravel博客应用性能对比分析详解