.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
相关产品推荐
相关产品推荐

