The speed comparison of the go language and ASP. NET's generic handlers when processing Web requests

Source: Internet
Author: User

The speed comparison of the go language and ASP. NET's generic handlers when processing Web requests

1, first write a Go language simple Web program, return a helloword!

Package Mainimport (f"FMT"    "Log"    "net/http"    //"Strings") Func sayhelloname (w http. Responsewriter, R*http. Request) {//R.parseform ()//f.println (r.form)//f.println ("path", R.url. Path)//f.println ("scheme", R.url. Scheme)//f.println (r.form["Url_long"])//for k, V: = range R.form {//f.println ("Key:", K, "Val:", Strings. Join (V, ","))//    }f.fprintln (W,"Hello world!")}func Main () {http. Handlefunc ("/", Sayhelloname) Err:= http. Listenandserve (": 8080", nil)ifErr! =Nil {log. Fatal ("Listenandserve:", Err)}}

2, build an ASP. HANDLER1.ASHX general Handler, and run in IIS.

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;namespacetestweb{/// <summary>    ///Summary description of Handler1/// </summary>     Public classHandler1:ihttphandler { Public voidProcessRequest (HttpContext context) {context. Response.Write ("Hello world!"); }         Public BOOLisreusable {Get            {                return false; }        }    }}

3, write a console program in C #, used to simulate the initiation of 10,000 requests, speed comparison:

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Net;usingSystem.Text;namespacetestspeed{classProgram {Static voidMain (string[] args) {WebClient WC=NewWebClient (); DateTime DT1=DateTime.Now;  for(inti =0; I <10000; i++)            {                varresult = WC. Downloadstring ("http://localhost:48563/handler1.ashx?t="+DateTime.Now.Ticks); } DateTime DT2=DateTime.Now; Console.WriteLine ("ASP. NET General handler time:"+ (DT2-dt1).            TotalMilliseconds); WebClient WC2=NewWebClient (); DateTime DT3=DateTime.Now;  for(inti =0; I <10000; i++)            {                varresult = WC2. Downloadstring ("http://127.0.0.1:8080/?t="+DateTime.Now.Ticks); } DateTime dt4=DateTime.Now; Console.WriteLine ("Go language:"+ (DT4-DT3).        TotalMilliseconds); }    }}

4. Test results:

Go language spents: 811.0464ms

ASP. NET General processing program: 14017.8017MS

5, Conclusion: Go is not the general FAST!!!! 17 times times the difference!!!

The speed comparison of the go language and ASP. NET's generic handlers when processing Web requests

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.