2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

.Net7 ネイティブ出力を試してみた

Last updated at Posted at 2023-02-07

概要

VSCode + C# + .Net 7で自作マスターデータツールをネイティブ出力して実行結果の共有

背景

.Net Core3.1で開発していたが2022/12でサポートが切れてしまったので.Net 7に移行
奇数バージョンは18ヶ月サポート(STS)で、偶数バージョンは36ヶ月サポート(LTS)なので
.Net 6を使うか.Net 8が出るまで待つか迷ったが、.Net 7にネイティブ出力機能があったので試してみた

環境

Visual Studio Code: 1.74.3 (user setup)
 C# for Visual Studio Code (powered by OmniSharp).:1.25.4
.Net Framework SDK:7.0.2

ビルド環境

4パターンのビルドを行い、実行ファイルサイズや動作速度を比較する

.Net Core3.1

dotnet publish -c Release -r win-x64 --self-contained true /p:PublishSingleFile=true /p:PublishTrimmed=true
  • シングルEXEファイル
  • ユーザーのランタイムインストール不要
  • トリミング

.Net 7 (Core3.1と同じ)

dotnet publish -c Release -r win-x64 --self-contained true /p:PublishSingleFile=true /p:PublishTrimmed=true
  • シングルEXEファイル
  • ユーザーのランタイムインストール不要
  • トリミング

.Net 7 (トリミングなし)

ビルドコマンド

dotnet publish -c Release -r win-x64 --self-contained true /p:PublishSingleFile=true
  • シングルEXEファイル
  • ユーザーのランタイムインストール不要

.Net 7 (ネイティブ)

dotnet publish -c Release -r win-x64 --self-contained true /p:PublishAot=true
  • シングルEXEファイル
  • ネイティブEXE
  • トリミングは自動的にされるっぽい

動作比較

解析Excel数: 414
解析総セル数: 2,624,362

個別計測

Core3.1 .Net 7(Coreと同じ) .Net 7(トリミングなし) .Net 7(ネイティブ)
Exeサイズ 43,490KB 18,708KB 71,980KB 21,259KB
Excel解析時間 2.783秒 3.405秒 2.583秒 1.944秒
バイナリ出力時間 0.261秒 0.299秒 0.183秒 0.158秒
C#コード出力時間 0.196秒 0.204秒 0.124秒 0.120秒
csv出力時間 0.461秒 0.546秒 0.301秒 0.197秒
htmlマニュアル出力時間 0.063秒 0.064秒 0.030秒 0.030秒
総合時間 3.896秒 4.710秒 3.304秒 2.468秒

順位表

Core3.1 .Net 7(Coreと同じ) .Net 7(トリミングなし) .Net 7(ネイティブ)
Exeサイズ 3位 1位 4位 2位
実行速度 3位 4位 2位 1位

結果

ネイティブ

総合的にバランスが良いのがネイティブという結果になった
欠点としては、WindowsとLinuxのみでmacOSには非対応ということだ
このツールはWindows、macOS、Linuxの3プラットフォームで提供しているため、macOSだけは別のビルドを使う必要がある

.Net 7(Coreと同じ)

ファイルサイズが一番小さいが、実行速度は一番遅い結果となった
.NetCore3.1と同じビルドオプションなのに実行速度が遅くなるのは気になる
.NetCore3.1と比べてファイルサイズが大きく減るのは、OSSもトリミングを行っているからのようだ

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?