朋友们,你们好!

近来,我听到了大量的关于新出的 .NET Core 和其性能的讨论,尤其在 Web 服务方面的讨论更甚。

因为是新出的,我不想立马就比较两个不同的东西,所以我耐心等待,想等发布更稳定的版本后再进行。

本周一(8 月 14 日),微软发布 .NET Core 2.0 版本,因此,我准备开始。您们认为呢?

如前面所提的,我们会比较它们相同的东西,比如应用程序、预期响应及运行时的稳定性,所以我们不会把像对 JSON 或者 XML 的编码、解码这些烦多的事情加入比较游戏中来,仅仅只会使用简单的文本消息。为了公平起见,我们会分别使用 Go 和 .NET Core 的 MVC 架构模式。

参赛选手

Go (或称 Golang): 是一种快速增长的开源编程语言,旨在构建出简单、快捷和稳定可靠的应用软件。

用于支持 Go 语言的 MVC web 框架并不多,还好我们找到了 Iris ,可胜任此工作。

Iris: 支持 Go 语言的快速、简单和高效的微型 Web 框架。它为您的下一代网站、API 或分布式应用程序奠定了精美的表现方式和易于使用的基础。

C#: 是一种通用的、面向对象的编程语言。其开发团队由 Anders Hejlsberg 领导。

.NET Core: 跨平台,可以在极少时间内开发出高性能的应用程序。

在下载和安装好这些软件后,还需要为 Go 安装 Iris。安装很简单,仅仅只需要打开终端,然后执行如下语句:

goget-u github.com/kataras/iris

基准

硬件

处理器: Intel(R) Core(TM) i7–4710HQ CPU @ 2.50GHz 2.50GHz

内存: 8.00 GB

软件

操作系统: 微软 Windows [10.0.15063 版本], 电源计划设置为“高性能”

两个应用程序都通过请求路径 “api/values/{id}” 返回文本“值”。

.NET Core MVC

可以使用 dotnet new webapi 命令创建项目,其 webapi 模板会为您生成代码,代码包含 GET 请求方法的 返回“值”。

源代码:

usingSystem;

usingSystem.Collections.Generic;

usingSystem.IO;

usingSystem.Linq;

usingSystem.Threading.Tasks;

usingMicrosoft.AspNetCore;

usingMicrosoft.AspNetCore.Hosting;

usingMicrosoft.Extensions.Configuration;

usingMicrosoft.Extensions.Logging;

namespacenetcore_mvc

{

publicclassProgram

{

publicstaticvoidMain(string[]args)

{

BuildWebHost(args).Run();

}

publicstaticIWebHostBuildWebHost(string[]args)=>

WebHost.CreateDefaultBuilder(args)

.UseStartup()

.Build();

}

}usingSystem;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Threading.Tasks;

usingMicrosoft.AspNetCore.Builder;

usingMicrosoft.AspNetCore.Hosting;

usingMicrosoft.Extensions.Configuration;

usingMicrosoft.Extensions.DependencyInjection;

usingMicrosoft.Extensions.Logging;

usingMicrosoft.Extensions.Options;

namespacenetcore_mvc

{

publicclassStartup

{

publicStartup(IConfigurationconfiguration)

{

Configuration=configuration;

}

publicIConfigurationConfiguration{get;}

// This method gets called by the runtime. Use this method to add services to the container.

publicvoidConfigureServices(IServiceCollectionservices)

{

services.AddMvcCore();

}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

publicvoidConfigure(IApplicationBuilderapp,IHostingEnvironmentenv)

{

app.UseMvc();

}

}

}usingSystem;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Threading.Tasks;

usingMicrosoft.AspNetCore.Mvc;

namespacenetcore_mvc.Controllers

{

// ValuesController is the equivalent

// `ValuesController` of the Iris 8.3 mvc application.

[Route("api/[controller]")]

pu