ASP. NET Core vs. Golang Web simple contrast test
Recently, because the job needs to touch the go language, and just like ASP. NET core release RC2, want to do a simple contrast test.
Here is the test environment:
CPU:E3-1230 v2
Memory: 16G
The computer is a bit of a force
Operating system: Centos7.0 (Virtual machine single core 2G memory)
ASP. NET Core RC2
Golang v1.7beta1
Here are the respective codes:
Go
123456789101112131415161718192021222324252627 |
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#
12345678910111213141516171819202122232425262728293031 |
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>();
});
}
}
|
are simple routes and simple return strings
Here are the test results
Go
ASP. NET Core
From the test results, ASP. NET core is better, including response time and number of concurrency. Supposedly go should be faster than. NET Core. I hope you will do more contrast test to refute me, I test n times is the result
However, in a Windows environment, Golang can be around 6000 concurrent, while. NET core is still more than 4,600, but the response speed. NET core is still faster than Golang, which I am a little puzzled. It's supposed to be. NET The world is right, haha
Recently, we have tested ASP. NET core, and found that it is really very, welcome to try
Fix test: http://www.cnblogs.com/gengzhe/p/5561718.html
NET Core and Golang Web