0
3

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 3 years have passed since last update.

【C#】.NET6でBlazor WebAssemblyのAOTを試してパフォーマンスを測定してみた

Last updated at Posted at 2021-11-18

初投稿です。

導入

ついにきましたね、.NET 6。
この記事( https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-6/#blazor-and-mono )によると
Blazor WebAssemblyにAOTコンパイルが実装され16倍早くなったらしいのですが、実際どれくらい早くなったか試してみました。

測定内容

10^6以下の素数を列挙するのにかかる時間を測定してみました。n=10^6として以下の関数の実行にかかる時間の測定を10回行い、平均と最大をとりました。
Blazor WebAssemblyは.NET6でReleaseビルド、AOTあり/なしを測定しました。
比較用に.NET6でのConsoleアプリケーションでの結果もとりました。
AOTを有効にするには公開(Publish)を実行する必要があります、普通に実行するだけではうまくいきません。
ちなみに、AOTなしに関しては.NET5/.NET6で差がみられなかったので.NET5は省略しています。

private IEnumerable<int> FindPrimes(int n)
{
    if (n < 0)
    {
        return Array.Empty<int>();
    }

    var isPrime = new bool[n + 1];
    Array.Fill(isPrime, true);
    isPrime[0] = false;
    isPrime[1] = false;

    for (int i = 2; i < isPrime.Length; i++)
    {
        if (!isPrime[i])
        {
            continue;
        }
        for (int j = i << 1; j < isPrime.Length; j += i)
        {
            isPrime[j] = false;
        }
    }

    return isPrime.Select((x, i) => (x, i)).Where(tuple => tuple.x).Select(tuple => tuple.i);
}

環境

  • OS Windows10 64bit(21H2)
  • CPU Ryzen7 1700 (@3.7Ghz)
  • RAM DDR4-3000 16GB (十分な空きあり)

結果

環境 平均値 最大値
Blazor AOTなし 1986ms 1995ms
Blazor AOTあり 574ms 579ms
Console 50.8ms 124ms

考察

純粋な計算での比較でしたが3.4倍以上は高速化されており、効果は大きいようです。
しかし依然としてコンソールアプリケーションよりは10倍以上遅い
もう少し早くなってくれるといいんですがね、今後に期待しましょう。

0
3
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
0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?