You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 7编译为WASM为何比原生JS慢16倍?

.NET 7 WASM与原生JS性能基准测试对比

我开展了简单的基准测试,发现编译为WASM的.NET 7运行速度是原生JS的1/16。测试代码及结果如下:

C#测试代码

namespace Benchmark
{
    public partial class MainJS
    {
        public static async Task Main()
        {
            var watch = new System.Diagnostics.Stopwatch();

            watch.Start();
            Int64 x = 0;
            for (int i = 0; i < 100000000; i++)
                x += i;
            watch.Stop();

            Console.WriteLine($"Execution Time: {watch.ElapsedMilliseconds} ms {x}"
        }
    }
}

运行结果

Execution Time: 16482 ms 4999999950000000

原生JS测试代码

console.time("a")
let x = 0;
for (i=0; i<100000000; i++)
    x += i
console.timeEnd("a")
console.log(x)

运行结果

a: 1084.294921875 ms
4999999950000000

如此糟糕的运行性能,让我难以发现.NET WASM在Web应用中的优势。

内容的提问来源于stack exchange,提问作者Gillespie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 13:10:49