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