Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-06-06 19:50:50
Original
2033 people have browsed it

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 (65112);

        }

    }

}

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template