对于已发布的应用程序(以及独立的.NET Core应用程序),dotnet的运行速度与dotnet的速度

The .NET Core team really prides themselves on performance. However, it's not immediately obvious (as with all systems) if you just do Hello World as a developer. Just today I was doing a Ruby on Rails app in Development Mode with mruby - but that's not what you'd go to production with.

.NET Core团队确实以性能为荣。 但是,如果您只是以开发人员的身份从事Hello World的工作,那么(与所有系统一样)并不是立即显而易见的。 就在今天,我正在使用mruby在“开发模式”下开发Ruby on Rails应用程序-但这不是您要使用的产品。

Let's look at a great question I got today on Twitter.

让我们看看我今天在Twitter上遇到的一个重要问题

@shanselman @davidfowl Is it normal for dotnet run on the latest .net core 2.0 preview 2 bits to take 4 seconds to run? pic.twitter.com/wvD2aqtfi0

— Jerome Terry (@jeromeleoterry)

@shanselman @davidfowl dotnet在最新的.net core 2.0预览版上运行2位需要4秒钟才能正常运行吗? pic.twitter.com/wvD2aqtfi0

-Jerome Terry(@jeromeleoterry) June 28, 2017 ,2017年6月28日

Dotnet Run-在开发中构建并运行源代码(Dotnet Run - Builds and Runs Source Code in Development)

install .NET Core 2.0 Preview - this person is on a Mac, but you can use Linux or Windows as well - then do just this:

安装.NET Core 2.0 Preview-这个人在Mac上,但是您也可以使用Linux或Windows-然后执行以下操作:

$ dotnet new console
$ dotnet run

It'll be about 3-4 seconds. dotnet is the SDK and dotnet run will build and run your source code. Here's a short bit from the docs:

大约需要3-4秒。 dotnet是SDK,dotnet运行将构建并运行您的源代码。 这是文档中的一小段内容:

The dotnet run command provides a convenient option to run your application from the source code with one command. It's useful for fast iterative development from the command line. The command depends on the dotnet build command to build the code. Any requirements for the build, such as that the project must be restored first, apply to dotnet run as well.

dotnet run命令提供了一个方便的选项,可以使用一个命令从源代码运行您的应用程序。 从命令行进行快速迭代开发非常有用。 该命令取决于dotnet build命令来构建代码。 构建的任何要求(例如必须首先还原项目)也适用于dotnet run

While this is super convenient, it's not totally obvious that dotnet run isn't something you'd go to production with (especially Hello World Production, which is quite demanding! ;) ).

尽管这非常方便,但并不是完全不希望将dotnet运行到生产环境中(尤其是Hello World Production,这是相当苛刻的要求;;))。

Dotnet发布然后将Dotnet YOUR.DLL用于生产 (Dotnet Publish then Dotnet YOUR.DLL for Production)

Instead, do a dotnet publish, note the compiled DLL created, then run "dotnet tst.dll."

而是,进行dotnet发布,记下已创建的已编译DLL,然后运行“ dotnet tst.dll”。

For example:

例如:

C:\Users\scott\Desktop\tst> dotnet publish
Microsoft (R) Build Engine version 15.3 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

tst -> C:\Users\scott\Desktop\tst\bin\Debug\netcoreapp2.0\tst.dll
tst -> C:\Users\scott\Desktop\tst\bin\Debug\netcoreapp2.0\publish\
C:\Users\scott\Desktop\tst> dotnet run .\bin\Debug\netcoreapp2.0\tst.dll
Hello World!

On my machine, dotnet run is 2.7s, but dotnet tst.dll is 0.04s.

在我的机器上,dotnet运行时间是2.7s,但是dotnet tst.dll是0.04s。

.NET Core is fast

点网发布-自包含 (Dotnet publish --self-contained)

I could then publish a complete self-contained app - I'm using Windows, so I'll publish for Windows but you could even build on a Windows machine but target a Mac runtime, etc and that will make a \publish folder.

然后,我可以发布一个完整的自包含应用程序-我正在使用Windows,所以我将针对Windows进行发布,但是您甚至可以在Windows机器上构建但以Mac运行时为目标,等等,这将创建一个\ publish文件夹。

C:\Users\scott\Desktop\tst> dotnet publish  --self-contained -r win10-x64
Microsoft (R) Build Engine version 15.3 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

tst -> C:\Users\scott\Desktop\tst\bin\Debug\netcoreapp2.0\win10-x64\tst.dll
tst -> C:\Users\scott\Desktop\tst\bin\Debug\netcoreapp2.0\win10-x64\publish\
C:\Users\scott\Desktop\tst> .\bin\Debug\netcoreapp2.0\win10-x64\publish\tst.exe
Hello World!

Note in this case I have a "Self-Contained" app, so all of .NET Core is in that folder and below. Here I run tst.exe, not dotnet.exe because now I'm an end-user.

请注意,在这种情况下,我有一个“自包含”应用程序,因此所有.NET Core都位于该文件夹中和下方。 在这里,我运行tst.exe,而不是dotnet.exe,因为现在我是最终用户。

The results of a published .NET Core App

I hope this helps clear things up.

我希望这有助于清理问题。

翻译自: https://www.hanselman.com/blog/speed-of-dotnet-run-vs-the-speed-of-dotnet-for-published-apps-plus-selfcontained-net-core-apps

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值