最近因為工作需要接觸了go語言,又恰好asp.net core發布RC2,就想簡單做個對比測試。
下面是測試環境:
CPU:E3-1230 v2
內存:16G
電腦有點不給力
操作系統:Centos7.0(虛擬機單核2G內存)
asp.net core rc2
golang v1.7beta1
下面是各自的代碼:
go
package main import ( "fmt" "net/http" ) func main() { fmt.Println("This is webserver base!") //第一個參數為客戶端發起http請求時的接口名,第二個參數是一個func,負責處理這個請求。 http.HandleFunc("/login", loginTask) //服務器要監聽的主機地址和端口號 err := http.ListenAndServe("192.168.199.236:8081", nil) if err != nil { fmt.Println("ListenAndServe error: ", err.Error()) } } func loginTask(w http.ResponseWriter, req *http.Request) { //獲取客戶端通過GET/POST方式傳遞的參數 req.ParseForm() fmt.Fprint(w, "Hello World!") }
C#
public class MyHandlerMiddleware { // Must have constructor with this signature, otherwise exception at run time public MyHandlerMiddleware(RequestDelegate next) { // This is an HTTP Handler, so no need to store next } public async Task Invoke(HttpContext context) { await context.Response.WriteAsync("Hello World!"); } // ... } public class Startup { public void ConfigureServices(IServiceCollection services) { } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app) { app.MapWhen(context => { return context.Request.Path.ToString().EndsWith("jjj.go"); }, ap => { ap.UseMiddleware<MyHandlerMiddleware>(); }); } }
都是簡單路由和簡單返回字符串
下面是測試結果
go
asp.net core
從測試結果看,asp.net core更好一些,包括響應時間和並發數。按理說go應該比.net core快才對。希望各位大神再多做對比測試來反駁我,我測試N次后都是這個結果
不過在windows環境下,golang的並發能到6000左右,而.net core依然在4600多,不過響應速度.net core依然比golang快一些,這個我有點費解。
最近反復對asp.net core進行測試,發現真的非常給力,歡迎大家多多嘗試
修正測試:http://www.cnblogs.com/gengzhe/p/5561718.html